View Full Version : Plotting bar graphs using QwtPlotHistogram
penny
4th January 2011, 05:39
I need to plot bar graphs, such that not all of them begin from the axis.
If i use QwtPlotHistogram, i can plot all data but starting from the axis.
I have attached an image showing how i want my plot to look.
Any suggestions?
mohini
4th January 2011, 07:01
try overlapping the existing plot with another plot (disable its color)
Not sure if its a correct method But I got similar plot by doing this....
Uwe
4th January 2011, 07:38
i can plot all data but starting from the axis.
What type of data do yo have:
- [y1,y2] = f( x );
- [y1,y2] = f( [x1, x2] )
Or do you simply have an ordered array of [y1,y2] intervals that are unrelated to any x value ( beside of their position in the array ) ?
Uwe
penny
4th January 2011, 08:42
I have just an ordered array [y1,y2], unrelated to any x value
Uwe
4th January 2011, 09:47
Then better implement your own type of plot item.
Derive from QwtPlotSeriesItem and use samples like this:
class YourSample
{
public:
YourSample();
YourSample( const QwtInterval &, const QwtInterval & );
bool operator==( const YourSample & ) const;
bool operator!=( const YourSample & ) const;
//! Interval
QwtInterval interval[2];
};
Then your series data object can return [ index - 0.5 , index + 0.5 [ as one interval and the other interval from your array.
class YourSeriesData: public QwtSeriesData<YourSample>
{
public:
YourSeriesData( const QVector<QwtInterval> &intervals):
m_intervals( intervals )
{
}
virtual size_t size() const
{
return m_intervals.size();
}
virtual YourSample sample( size_t i ) const
{
QwtInterval interval( i - 0.5, i + 0.5, QwtInterval:: ExcludeMaximum);
return YourSample( interval, m_intervals[i] );
}
virtual QRectF boundingRect() const
{
double xMin = -0.5;
double xMax = size() + 0.5;
double yMin = ...;
double yMax = ...;
return QRectF( xMin , yMin, xMax - xMin, yMax - yMin );
}
};
Of course the code above is for vertical bars ( v.v. to your screenshot ).
Implementing the virtual methods for your plot item should be straight forward ( or copy and adopt your code from QwtPlotHistogram ).
Uwe
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.