QCharts automatic axes scaling problem
I want to plot data with QCharts. My idea is to create a chart and series in the constructor and add the series to the chart. Then I'd like like to add data to the series in a function and add axes to the chart that are scaled to the data points.
createDefaultAxes() seems to do just what I want, but the scaling only works if I add the series to the chart after adding the data points.
My code looks like so:
QLineSeries *series = new QLineSeries(); QChart *chart = new QChart(); chart->setTitle("Simple line chart example"); ui->chartView->setChart(chart); ui->chartView->setRenderHint(QPainter::Antialiasing); chart->addSeries(series); // <- axes _not_ scaled properly series->append(0, 0); series->append(2, 4); series->append(3, 8); series->append(7, 4); series->append(10, 5); // chart->addSeries(series); // <- axes scaled properly chart->createDefaultAxes();
I don't really understand why it makes a difference, where series is added to chart. In the end, it's just a pointer, right?
Does anyone have an idea how I can tell chart that its series has updated?
Any help is appreciated :-)
Can anyone just confirm that it at least should work? Or am I reading the documentation wrong? Otherwise I'd file a bug...
From a quick look at the documentation, I haven't see anything stating that adding points to a series after it has been added to a chart should trigger anything. The QAstractSeries class also doesn't seem to offer anything related to triggering an update.