PDA

View Full Version : Repaint QSplineSeries



Blitzor DDD
14th May 2017, 16:40
Hello!

I would like dynamically rewrite chart, generated by QSplineSeries.
I am trying to achieve it this way:


QSplineSeries* series_for_Vy= new QSplineSeries();
QChart* chart_for_Vy = new QChart();
QGroupBox *Widget::set_splinechart_Vy()
{

int n ; //номер шага по времени
number_of_step_for_Vy = new QLineEdit("steps");

series_for_Vy->append(3,3);
series_for_Vy->append(2,5);

chart_for_Vy->legend()->hide();
chart_for_Vy->addSeries( series_for_Vy);
chart_for_Vy->setTitle("Vy (N)");
chart_for_Vy->createDefaultAxes();
chart_for_Vy->axisY()->setRange(0, 10);
chart_for_Vy->axisX()->setRange(0,10);
chart_for_Vy->axisX()->setTitleText("Number of Node, N");
chart_for_Vy->axisY()->setTitleText("Velocity, Vy");



QChartView *chartView = new QChartView(chart_for_Vy);


slider_for_Vy = new QSlider(Qt::Orientation::Horizontal);
slider_for_Vy->setRange(1,999);


QVBoxLayout *vert = new QVBoxLayout;
QHBoxLayout *horiz = new QHBoxLayout;
vert->addWidget(chartView);
// vert->addWidget(slider);
horiz->addWidget(slider_for_Vy,Qt::AlignLeft);horiz->addWidget(number_of_step_for_Vy);
vert->addLayout(horiz);
QGroupBox* groupbox = new QGroupBox("Y-component of velocity");
groupbox->setLayout(vert);
//connect(number_of_step_for_Vy,SIGNAL(textEdited(QS tring)),SLOT(update()));
return groupbox;
}

void Widget::plot_Velocity_Y()
{
series_for_Vy->clear();
series_for_Vy->append(3,3);
series_for_Vy->append(2,9);
chart_for_Vy->clearFocus();
chart_for_Vy->addSeries( series_for_Vy);

}

But when program comes to SLOT plot_Velocity_Y, it does not change and lines appear:
"Can not add series. Series already on the chart."

How to handle this?

d_stranz
14th May 2017, 17:30
You're trying to add the same series more than once (that is, QSplineSeries * series_for_Vy has already been added to the chart). The fact that you changed the data in the series makes no difference.

You probably need to do this:

- remove the series from the chart (QChart::removeSeries())
- change the series data
- add the series back to the chart (QChart::addSeries())

You may not actually need to remove and add the series, but from what I remember of QChart, changing the data in the series may not result in an update to the chart.

Blitzor DDD
14th May 2017, 20:57
Thank you!

scgrant327
15th May 2017, 15:20
I'm using QML for my charts, but I have been able to achieve updating the series without removing and recreating it...


wavgSeries.remove(0);
wavgSeries.append(appWin.wxMsec,appWin.wxWavg);

Basically, removing the first element in the series, then just appending a new one...

--SamG