PDA

View Full Version : QwtPlotHistogram question



fantom
31st March 2011, 14:56
I want to set text on the rectangles of a QwtPlotHistogram. I attached an example how i want to look like. I took as a start the tv plot example and the set values function looks like this:



void Histogram::setValues(uint numValues, int*values)
{
QVector<QwtIntervalSample> samples(numValues);
for ( uint i = 0; i < numValues; i++ )
{
QwtInterval interval(double(i), i + 1.0);
interval.setBorderFlags(QwtInterval::ExcludeMaximu m);

samples[i] = QwtIntervalSample(values[i], interval);
}

setData(new QwtIntervalSeriesData(samples));
}



Could you give me an example how it has to look like with the text?

Thank you

Uwe
2nd April 2011, 17:10
Could you give me an example how it has to look like with the text?

When the text is available from the sample you can overload QwtPlotHistogram::drawColumn:


virtual void YourHistogram::drawColumn( QPainter *painter,
const QwtColumnRect &rect, const QwtIntervalSample &sample ) const
{
QwtPlotHistogram::drawColumn( painter, rect, sample );

// now draw your text
...
}

Otherwise overload QwtPlotHistogram::drawColumns:


virtual void YourHistogram::drawColumns( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to ) const
{
QwtPlotHistogram::drawColumns( painter, xMap, yMap, from, to );

for ( int i = from; i <= to; i++ )
{
const QwtIntervalSample sample = d_series->sample( i );
const QwtColumnRect rect = columnRect( sample, xMap, yMap );

// now draw your text
}
}

Uwe

hind
25th March 2013, 09:05
I have a question which may be relevant to this thread. Forgive me if I chose the wrong place. Here's the pic based on the tvplot example:
8840
So how do I place labels displaying the value of each sample right on the top of each column? Or maybe some other reletive positions are fine too.
I thought the QwtPlotMarker might be the one but it seems not able to control the position of the label as I need.
Thanks in advance!

Uwe
28th March 2013, 09:43
Posting a question rbelow the answer for the same question ?

Uwe

PS: Qwt 6.1 offers new plot items for bar charts - something different than what QwtPlotHistogram is made for.