Results 1 to 5 of 5

Thread: Curve and horizontal bar chart from same set of samples?

  1. #1
    Join Date
    Feb 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Curve and horizontal bar chart from same set of samples?

    Hi,

    I'm experimenting with Qwt for my plotting needs. It's working very well, but I have a question: Is it possible to make a curve plot and a horizontal bar plot from the same set of samples?

    E.g. like this:


    Qt Code:
    1. // Create a test curve
    2. QVector<QPointF> samples;
    3. for (double y = 0.0; y < 1000.0; y += 10.0) {
    4. auto x = 0.1 + 0.08 * std::sin(y / 50.0);
    5. samples.append(QPointF(x, y));
    6. }
    7.  
    8. // Create a bar chart
    9. auto barChart = new QwtPlotBarChart("Test Bar Chart");
    10. barChart->setSamples(samples);
    11. barChart->setXAxis(QwtPlot::xTop);
    12. barChart->setRenderHint(QwtPlotItem::RenderAntialiased);
    13. //barChart->setOrientation(Qt::Horizontal);
    14. barChart->attach(this);
    15.  
    16. // Create a curve
    17. auto curve = new QwtPlotCurve("Test Curve");
    18. curve->setSamples(samples);
    19. curve->setXAxis(QwtPlot::xTop);
    20. curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    21. curve->attach(this);
    To copy to clipboard, switch view to plain text mode 

    With the above code, I get the result in the attache without_horizontal_alignment.png. If I uncomment the
    Qt Code:
    1. barChart->setOrientation(Qt::Horizontal)
    To copy to clipboard, switch view to plain text mode 
    line, I get the result in with_horizontal_alignment.png.

    If I *also* switch the x / y values in my samples vector, I can get the correct result for the bar chart item (see working.png), but then the curve is wrong.

    I'm looking for a way to use the same vector of samples and get the look I want ("vertical" line chart, but "horizontal" bar chart).

    Thanks in advance.

    without_horizontal_alignment.png:

    without_horizontal_alignment.jpg

    with_horizontal_alignment.png:

    with_horizontal_alignment.jpg

    working.png:

    working.jpg

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

    Default Re: Curve and horizontal bar chart from same set of samples?

    Is it possible to make a curve plot and a horizontal bar plot from the same set of samples?
    Have you considered to use QwtPlotCurve::Sticks ?
    I'm looking for a way to use the same vector of samples and get the look I want ("vertical" line chart, but "horizontal" bar chart).
    All setSamples methods are only convenience ending up in setData. So you could derive from QwtPointSeriesData returning a sample with x/y being swapped.

    Uwe

  3. #3
    Join Date
    Feb 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve and horizontal bar chart from same set of samples?

    Thanks a lot for the quick reply Uwe.

    Quote Originally Posted by Uwe View Post
    Have you considered to use QwtPlotCurve::Sticks ?
    Sorry, my example was not quite complete (should have used setMargin(0) and setSpacing(0) on the bar chart). I actually want the look of a real bar chart, since my data points are measurements taken by a spectrometer over a segment of a rock core, so it makes sense to have actual bars that span over this segment. In the end I also think I want to let the user activate error bars, and I think those looks best on a bar chart.

    All setSamples methods are only convenience ending up in setData. So you could derive from QwtPointSeriesData returning a sample with x/y being swapped.
    I see, yes in the end I think I'll probably make a custom QwtPointSeriesData which is backed by my real data store (a dataset in a HDF5 file).

    It was just initially that I was using a QVector of points because it was easy to generate.

    But it's good that you confirm that I'll have to swap x/y in order to get the look I want. I somehow thought I'd be able to get the bars to go horizontally using the same input vector as I used for the curve.

    (In my real app, I'm not planning to have the two shown at the same time, but let the user switch between line and bar chart, and it would have been convenient if I could use the exact same input data.)

    Thanks for the answers!
    Last edited by estan; 19th September 2016 at 11:59.

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

    Default Re: Curve and horizontal bar chart from same set of samples?

    I actually want the look of a real bar chart, since my data points are measurements taken by a spectrometer over a segment of a rock core, so it makes sense to have actual bars that span over this segment.
    QwtPlotHistogram might be an option here too. It is different to a bar chart as it displays [x1-x2, y] type of samples.

    Uwe

  5. #5
    Join Date
    Feb 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve and horizontal bar chart from same set of samples?

    Quote Originally Posted by Uwe View Post
    QwtPlotHistogram might be an option here too. It is different to a bar chart as it displays [x1-x2, y] type of samples.
    Ah, thanks. I'll have a look at that too.

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2013, 09:12
  2. Can't build samples
    By kalons in forum Installation and Deployment
    Replies: 5
    Last Post: 22nd December 2010, 19:06
  3. Replies: 4
    Last Post: 29th April 2010, 06:11
  4. BuddyList - samples
    By underlife in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 13:09
  5. How do you build QT without the samples??
    By Joachie in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2009, 21:16

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.