我应该如何添加和删除qchart系列?
QChart的主要问题是QChart如何存储QAxis和QSeries,QSeries本身是指QAxis。所有这些对象之间都是紧密连接的。
因此,而不是像这样的伪代码:
void someclass::set_series(QLineSeries*someQLineSeries){
somechart->removeAllSeries();
somechart->removeAllAxis();
somechart->addSeries(someQLineSeries);
}
我应该使用:
(zlineseries另外还存储2个指向其轴的指针)
void zhplotview::attach_dt_series(ZLineSeries *series)
if(chart)
{
qDebug()<<"NOT DELETED CHART";
if(viewer)
{
qDebug()<<"NOT DELETED VIEWER";
qDebug()<<"Okay. Try to clear old links and create chart again";
//let chart have 1 series
auto slist=chart->series();
ZLineSeries *old_series=dynamic_cast<ZLineSeries*>(slist.at(0));
old_series->detachAxis(old_series->axis_x);
old_series->detachAxis(old_series->axis_y);
chart->removeAxis(old_series->axis_x);
chart->removeAxis(old_series->axis_y);
vbl->removeWidget(viewer);
chart->removeSeries(old_series);
disconnect(viewer);
disconnect(chart);
delete chart;
delete viewer;
}
else
{
qDebug()<<"chart is 0, but viewer not";
return;
}
}
chart=new QChart();
chart->addSeries(series);
chart->addAxis(series->axis_x,Qt::AlignBottom);
chart->addAxis(series->axis_y,Qt::AlignLeft);
series->attachAxis(series->axis_x);
series->attachAxis(series->axis_y);
viewer=new QZChartView(chart,this);
vbl->addWidget(viewer);
最佳答案
我知道已经过了三年,但是我为此使用了一些解决方法,也许对某人来说很有趣。
在每个增量上,我都会生成一个新图表,并替换旧图表。为了足够快,我将一些预先计算的数据保留在堆栈中。
关于c++ - QT QCharts添加和删除系列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39171173/