If have a QLineSeries and a QChart.
I expected that appending a new point would automatically update the Chart. But found that the only way to get it to update the chart was this horrible code:
//
// Add the score and update the score chart
//
if (nullptr != scoreSeries)
scoreChart->removeSeries(scoreSeries);
else
{
scoreSeries = new QLineSeries(this);
scoreSeries->setName(tr("Score", "IDC_SCORE"));
scoreSeries->setPointsVisible(true);
connect(scoreSeries, &QLineSeries::hovered,
this, &ChartTab::scoreHovered);
}
scoreSeries->append(x, fScore);
scoreMap.emplace(name, size - 1);
scoreChart->addSeries(scoreSeries);
scoreChart->createDefaultAxes();
axes = scoreChart->axes(Qt::Horizontal);
for (const auto& p : axes)
{
QValueAxis* axis{ dynamic_cast<QValueAxis*>(p) };
if (axis)
{
axis->setRange(1.0, size);
axis->setTickAnchor(1.0);
axis->setTickType(QValueAxis::TicksDynamic);
axis->setTickInterval(interval);
}
}
I'm convinced that there's a better way to get the chart updated when I append to the line series but so far I've failed to find anything that actually works.
Please put me out of my misery and tell me how this should be done.
FWIW I'm using Qt 6.5.1 but I doubt that makes a great difference.