Results 1 to 4 of 4

Thread: QwtPlotHistogram question

  1. #1
    Join Date
    Feb 2011
    Posts
    22
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    1

    Default QwtPlotHistogram question

    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:

    Qt Code:
    1. void Histogram::setValues(uint numValues, int*values)
    2. {
    3. QVector<QwtIntervalSample> samples(numValues);
    4. for ( uint i = 0; i < numValues; i++ )
    5. {
    6. QwtInterval interval(double(i), i + 1.0);
    7. interval.setBorderFlags(QwtInterval::ExcludeMaximum);
    8.  
    9. samples[i] = QwtIntervalSample(values[i], interval);
    10. }
    11.  
    12. setData(new QwtIntervalSeriesData(samples));
    13. }
    To copy to clipboard, switch view to plain text mode 

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

    Thank you

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPlotHistogram question

    Quote Originally Posted by fantom View Post
    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:

    Qt Code:
    1. virtual void YourHistogram::drawColumn( QPainter *painter,
    2. const QwtColumnRect &rect, const QwtIntervalSample &sample ) const
    3. {
    4. QwtPlotHistogram::drawColumn( painter, rect, sample );
    5.  
    6. // now draw your text
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

    Otherwise overload QwtPlotHistogram::drawColumns:

    Qt Code:
    1. virtual void YourHistogram::drawColumns( QPainter *painter,
    2. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    3. int from, int to ) const
    4. {
    5. QwtPlotHistogram::drawColumns( painter, xMap, yMap, from, to );
    6.  
    7. for ( int i = from; i <= to; i++ )
    8. {
    9. const QwtIntervalSample sample = d_series->sample( i );
    10. const QwtColumnRect rect = columnRect( sample, xMap, yMap );
    11.  
    12. // now draw your text
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. #3
    Join Date
    Mar 2013
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    13

    Default Re: QwtPlotHistogram question

    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:
    图像 047.png
    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!

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPlotHistogram question

    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.

Similar Threads

  1. Replies: 1
    Last Post: 9th October 2013, 21:42
  2. Cannot find QwtPlotHistogram class
    By gabe.ayers in forum Qwt
    Replies: 3
    Last Post: 9th February 2011, 00:51
  3. Replies: 8
    Last Post: 5th January 2011, 12:51
  4. QwtPlotHistogram
    By yers in forum Qwt
    Replies: 4
    Last Post: 5th January 2011, 08:23
  5. Replies: 4
    Last Post: 4th January 2011, 10:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.