QChart : Update\rescale axis after series update
Unsolved
General and Desktop
-
So, how can i update axis after series update?
Example. Here i create chart:QChartView* view; QChart* chart= new QChart(); QLineSeries *series = new QLineSeries(); for(int i=0;i<50000;i++) { series->append(i,i); } chart->addSeries(series); QDateTimeAxis *axisX = new QDateTimeAxis; chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis *axisY = new QValueAxis; chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY);
Then, in some another place i'm replacing series:
QLineSeries *series=(QLineSeries*)(view->chart()->series().first()); QList<QPointF> list; for(int i=0;i<70000;i++) { list.append(QPointF(i,i-20)); } series->replace(list);
How can i update axis after this?
-
there is no easy way to do it, so it can be done something like that:
// create a pointer to old chart QChart* chartToDelete=NULL; if(view->chart()) { chartToDelete=view->chart(); } QChart* chart= new QChart(); QLineSeries *series = new QLineSeries(); // here you create Axis, attach them to series and so on view->setChart(chart); // here delete old chart delete chartToDelete;
-
On the QML side, I do this just by changing the 'min' and 'max' values when updating the series.
Doesn't that work on the C++ side as well:
http://doc.qt.io/qt-5/qvalueaxis.html#max-prop
http://doc.qt.io/qt-5/qvalueaxis.html#min-prop--Sam