Results 1 to 5 of 5

Thread: Plotting bar graphs using QwtPlotHistogram

  1. #1
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Plotting bar graphs using QwtPlotHistogram

    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?
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Plotting bar graphs using QwtPlotHistogram

    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....

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plotting bar graphs using QwtPlotHistogram

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

  4. #4
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Plotting bar graphs using QwtPlotHistogram

    I have just an ordered array [y1,y2], unrelated to any x value

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plotting bar graphs using QwtPlotHistogram

    Then better implement your own type of plot item.

    Derive from QwtPlotSeriesItem and use samples like this:

    Qt Code:
    1. class YourSample
    2. {
    3. public:
    4. YourSample();
    5. YourSample( const QwtInterval &, const QwtInterval & );
    6.  
    7. bool operator==( const YourSample & ) const;
    8. bool operator!=( const YourSample & ) const;
    9.  
    10. //! Interval
    11. QwtInterval interval[2];
    12. };
    To copy to clipboard, switch view to plain text mode 

    Then your series data object can return [ index - 0.5 , index + 0.5 [ as one interval and the other interval from your array.

    Qt Code:
    1. class YourSeriesData: public QwtSeriesData<YourSample>
    2. {
    3. public:
    4. YourSeriesData( const QVector<QwtInterval> &intervals):
    5. m_intervals( intervals )
    6. {
    7. }
    8.  
    9. virtual size_t size() const
    10. {
    11. return m_intervals.size();
    12. }
    13.  
    14. virtual YourSample sample( size_t i ) const
    15. {
    16. QwtInterval interval( i - 0.5, i + 0.5, QwtInterval:: ExcludeMaximum);
    17. return YourSample( interval, m_intervals[i] );
    18. }
    19.  
    20. virtual QRectF boundingRect() const
    21. {
    22. double xMin = -0.5;
    23. double xMax = size() + 0.5;
    24.  
    25. double yMin = ...;
    26. double yMax = ...;
    27.  
    28. return QRectF( xMin , yMin, xMax - xMin, yMax - yMin );
    29. }
    30. };
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. QwtPlotHistogram
    By yers in forum Qwt
    Replies: 4
    Last Post: 5th January 2011, 07:23
  2. Graphs in Qt
    By qtlinuxnewbie in forum Newbie
    Replies: 4
    Last Post: 20th February 2010, 12:01
  3. Plotting graphs in QGraphicsView using qwt
    By luis_claudio in forum Newbie
    Replies: 0
    Last Post: 14th September 2009, 19:47
  4. Best way to draw x,y graphs
    By steg90 in forum Newbie
    Replies: 1
    Last Post: 14th May 2007, 11:52
  5. Drawing graphs
    By steg90 in forum Newbie
    Replies: 4
    Last Post: 9th May 2007, 13:37

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.