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..
Code:
const qreal angularMin = 0;
const qreal angularMax = 360;
const qreal radialMin = 0;
const qreal radialMax = 100;
sat_plot = new QScatterSeries();
sat_plot
->setColor
(QColor(Qt
::blue));
sat_plot->setName("scatter");
sat_plot->setMarkerSize(10);
//sat_plot->append(20, 300); //<--- i can add these plots here, but not later in other function...
//sat_plot->append(40, 100);
//sat_plot->append(50, 0);
QPolarChart *sat_chart = new QPolarChart();
sat_chart->addSeries(sat_plot);
qreal polar_w = 1000;
qreal polar_h = 1000;
sat_chart->setPreferredSize(polar_h,polar_h);
QValueAxis *angularAxis = new QValueAxis();
angularAxis->setTickCount(17);
angularAxis->setLabelFormat("%d");
angularAxis->setShadesVisible(true);
QFont axFont
("Helvetica [Cronyx]",
8);
angularAxis->setLabelsFont(axFont);
sat_chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);
sat_chart->setMargins(QMargins::QMargins(0,0,0,0));
sat_chart->legend()->setVisible(false);
QValueAxis *radialAxis = new QValueAxis();
radialAxis->setTickCount(10);
radialAxis->setLabelFormat("");
sat_chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);
radialAxis->setRange(radialMin, radialMax);
angularAxis->setRange(angularMin, angularMax);
QChartView *chartView = new QtCharts::QChartView();
chartView->setChart(sat_chart);
chartView
->setRenderHint
(QPainter::Antialiasing);
I tried to use both
Code:
sat_plot->append(100,56);
and
Code:
sat_plot->insert(0,P)
I know i'm able to access the object from another function, because i can call and it clears the chart, also i can see that i am actually adding points to the chart with
Code:
sat_plot->points().size();
in qDebug which is incrementing.. i also checked
Code:
sat_plot->pointsVisible();
and it is true..
any ideas?
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.
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..
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 ):
Code:
series1.remove(0);
series1.append(incomingData.msec,incomingData.dataPoint);
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++.
Re: Dynamically updating QChart
Ok ill try that one also, thanks...
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.