Results 1 to 6 of 6

Thread: Dynamically updating QChart

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Question Dynamically updating QChart

    All,

    Ive successfully integrated the QPolarPlot into my application, however im only able to add data at the object creation. I have a database that im successfully pulling plotted data from, that is working (via qDebug i can see that data), however when i try to add points to the plot, they dont show up..

    code used to create the chart..

    Qt Code:
    1. const qreal angularMin = 0;
    2. const qreal angularMax = 360;
    3.  
    4. const qreal radialMin = 0;
    5. const qreal radialMax = 100;
    6.  
    7. sat_plot = new QScatterSeries();
    8. sat_plot->setColor(QColor(Qt::blue));
    9. sat_plot->setName("scatter");
    10. sat_plot->setMarkerSize(10);
    11. //sat_plot->append(20, 300); //<--- i can add these plots here, but not later in other function...
    12. //sat_plot->append(40, 100);
    13. //sat_plot->append(50, 0);
    14.  
    15. QPolarChart *sat_chart = new QPolarChart();
    16. sat_chart->addSeries(sat_plot);
    17.  
    18. qreal polar_w = 1000;
    19. qreal polar_h = 1000;
    20. sat_chart->setPreferredSize(polar_h,polar_h);
    21.  
    22. QValueAxis *angularAxis = new QValueAxis();
    23. angularAxis->setTickCount(17);
    24. angularAxis->setLabelFormat("%d");
    25. angularAxis->setShadesVisible(true);
    26.  
    27. QFont axFont("Helvetica [Cronyx]", 8);
    28. angularAxis->setLabelsFont(axFont);
    29. angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255)));
    30. sat_chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);
    31. sat_chart->setMargins(QMargins::QMargins(0,0,0,0));
    32. sat_chart->legend()->setVisible(false);
    33.  
    34. QValueAxis *radialAxis = new QValueAxis();
    35. radialAxis->setTickCount(10);
    36. radialAxis->setLabelFormat("");
    37. sat_chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);
    38.  
    39. radialAxis->setRange(radialMin, radialMax);
    40. angularAxis->setRange(angularMin, angularMax);
    41.  
    42. QChartView *chartView = new QtCharts::QChartView();
    43. chartView->setChart(sat_chart);
    44. chartView->setRenderHint(QPainter::Antialiasing);
    To copy to clipboard, switch view to plain text mode 

    I tried to use both
    Qt Code:
    1. sat_plot->append(100,56);
    To copy to clipboard, switch view to plain text mode 
    and

    Qt Code:
    1. QPoint p(23,43);
    2. sat_plot->insert(0,P)
    To copy to clipboard, switch view to plain text mode 

    I know i'm able to access the object from another function, because i can call
    Qt Code:
    1. sat_plot->clear();
    To copy to clipboard, switch view to plain text mode 
    and it clears the chart, also i can see that i am actually adding points to the chart with
    Qt Code:
    1. sat_plot->points().size();
    To copy to clipboard, switch view to plain text mode 
    in qDebug which is incrementing.. i also checked
    Qt Code:
    1. sat_plot->pointsVisible();
    To copy to clipboard, switch view to plain text mode 
    and it is true..

    any ideas?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dynamically updating QChart

    [RANT]The QChart library is one of the most poorly-designed of any Qt library. It is an embarrassment compared to everything else in Qt.[/RANT]

    Nonetheless. For one thing you don't attach any axes to your series. See QChart::addSeries(). I doubt this is the cause of your problem. The series *should* be emitting signals each time you modify or add a point - have you tried connecting to any of those to see if they are being emitted when you insert points?

    If they are, then it could be that for some reason the plot isn't listening for them. Try calling QGraphicsItem::update() (from which QChart / QPolarChart are derived) after making your changes.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Dynamically updating QChart

    thank you for the response... I was able to do what i needed although i think yours is better memory wise...

    and Ill agree with you on the design of the chart classes, it doesn't seem to have the functionality of other Qt Classes..

    i had to create the Chart object, attached it to a view, then in the same function im querying for the points, im destroying the scatterplot, creating a new one and assigning it to the chart object...

    ill post code when i have something worth showing..

  4. #4
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Lightbulb Re: Dynamically updating QChart

    I understand you are using c++ for your charts, but this may help....

    I use the QML charts, and am dynamically updating them by doing a 'remove' followed by and 'append'. I have 4 charts, 3 of which have a single series, and one which has 2 series.

    I define the each series at Chart creation, the populate the entire series with data from a MySQL DB... then as new data is added to the DB, I do this for each series ( as appropriate ):

    Qt Code:
    1. series1.remove(0);
    2. series1.append(incomingData.msec,incomingData.dataPoint);
    To copy to clipboard, switch view to plain text mode 

    This removes the first item from the series (the oldest), and appends the newest item as the last in the series... works like a charm.

    I was originally destroying and recreating each series... which worked, but this way is cleaner and is less effort.

    I would assume that since I can do this via QML, you could do it via C++.

  5. #5
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Dynamically updating QChart

    Ok ill try that one also, thanks...

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dynamically updating QChart

    Based on scgrant327's comment, it looks like the insert() method isn't causing the update like the remove() and append() methods. You could check with the debugger to step in and see what happens during your insert() call.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. qchart hide legend for part of series
    By marrierius in forum Newbie
    Replies: 5
    Last Post: 9th September 2021, 15:11
  2. contextMenuEvent works partially in QChart
    By marrierius in forum Newbie
    Replies: 0
    Last Post: 16th December 2016, 19:48
  3. Replies: 6
    Last Post: 7th January 2013, 17:30
  4. Replies: 5
    Last Post: 12th October 2009, 11:05
  5. Dynamically updating a qt application
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 15:55

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.