Results 1 to 5 of 5

Thread: Charts in QtQuick: creating a line series with bar sets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Charts in QtQuick: creating a line series with bar sets

    This question is admittedly a little odd, and convoluted.

    Let me start by acknowledging that it does not actually make sense to use a scatter/line/spline chart when there is no inherent relationship between y and x (i.e., y cannot reasonably be construed to be a function of x).

    The non-scientific reality is that many people simply want to see a trend line. Consider the case wherein a measurement is collected every day, and we are interested in charting monthly averages. The x axis is the month, and the y axis is the average value. Clearly, this is best modelled with a BarSet because of the nature of the data (and this becomes clear when we consider that we prefer "Sept" over 9 on the x axis). But the Powers That Be are insisting on a trend line. The problem is that a LineSeries is composed of one or more instances of XYSeries, and XYSeries consists of two real numbers (x and y).

    Can this be done using the QtChart module? If so, how might I go about it? Any insights are appreciated.

    (I'll update (and hopefully answer!) this question as I go along, but figured I'd get things rolling on this front.)

    Update:

    Before:

    Qt Code:
    1. BarSeries {
    2. id: barSeries
    3.  
    4. axisX: BarCategoryAxis { categories: dummyData.months }
    5.  
    6. BarSet {
    7. id: appetiteBars
    8.  
    9. label: "Appetite"
    10. values: dummyData.appetite
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    After:

    Qt Code:
    1. LineSeries {
    2. id: lineSeries
    3.  
    4. axisX: BarCategoryAxis { categories: dummyData.months }
    5.  
    6. XYPoint { x: 0; y: dummyData.appetite[0] }
    7. XYPoint { x: 1; y: dummyData.appetite[1] }
    8. XYPoint { x: 2; y: dummyData.appetite[2] }
    9. XYPoint { x: 3; y: dummyData.appetite[3] }
    10. XYPoint { x: 4; y: dummyData.appetite[4] }
    11. XYPoint { x: 5; y: dummyData.appetite[5] }
    12. }
    To copy to clipboard, switch view to plain text mode 

    My brain still rebels against doing this, and it's much more cumbersome to implement as a line series (i.e., per value, rather than dumping the whole array into a BarSet) but it works...
    Last edited by Urthas; 5th July 2016 at 00:04.

Similar Threads

  1. Qwt charts wtih large data set and multiple series
    By deepal_de in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2015, 15:31
  2. Replies: 0
    Last Post: 3rd March 2015, 09:00
  3. Replies: 3
    Last Post: 6th March 2014, 10:09
  4. Replies: 21
    Last Post: 8th December 2011, 02:18
  5. Creating images from sets of data.
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2008, 09:25

Tags for this Thread

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.