0

我尝试将两行 QSplineSeries 添加到一个 QChartView。

示例:

QSplineSeries *series = new QSplineSeries();
series->setName("spline");

series->append(0, 6);
series->append(2, 4);
series->append(3, 8);
series->append(7, 4);
series->append(10, 5);
*series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);

QChart *chart = new QChart();
chart->legend()->hide();
chart->addSeries(series);
chart->setTitle("Simple spline chart example");
chart->createDefaultAxes();
chart->axes(Qt::Vertical).first()->setRange(0, 10);

QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);

QMainWindow window;
window.setCentralWidget(chartView);
window.resize(400, 300);
window.show();

因此,显示了一行。一切都好!

我试着做这个(两行):

QSplineSeries *series1 = new QSplineSeries();
QSplineSeries *series2 = new QSplineSeries();

series1->setName("spl1");
series2->setName("spl2");

series1->append(0, 6);
series2->append(0, 4);
series1->append(3, 8);
series2->append(3, 4);
series1->append(10, 8);
series2->append(10, 5);

QChart *chart = new QChart();
chart->legend()->hide();

chart->addSeries(series1);
chart->addSeries(series2);

chart->setTitle("Two lines");
chart->createDefaultAxes();
chart->axes(Qt::Vertical).first()->setRange(0, 10);

QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);

QMainWindow window;
window.setCentralWidget(chartView);
window.resize(400, 300);
window.show();

但!没有显示任何线条(我想要两条线)。

如何解决?

你能帮助我吗?

谢谢!

4

0 回答 0