I am using QT 5.12. I extracted code sample from QtRPT library that I am using. Working with QChart, if only one series is present, then everything is good. I add the first series and call chart->createDefaultAxes();
First series has three points:
<value x="0.00" y="37.950"/>
<value x="0.10" y="41.050"/>
<value x="0.20" y="41.300"/>
The y axis in chart starts at 37.95 and ends on 41.30

The issue comes, when I add second series:
<value x="0.10" y="0.000"/>
<value x="0.20" y="9.000"/>
<value x="0.30" y="15.000"/>
Suddenly, the y axis starts at 0.0, but the first series looks like starting from 0.0 too! That is wrong. The points from first series are misplaced.

Code sample:
QChart *chart = new QChart();
auto series1 = new QLineSeries();
series->append(0.00, 37.950)
series->append(0.10, 41.050)
series->append(0.20, 41.300)
chart->addSeries(series1);
auto series2 = new QLineSeries();
series2->append(0.10, 0.000)
series2->append(0.20, 9.000)
series2->append(0.30, 15.000)
chart->addSeries(series2);
chart->createDefaultAxes();
Could you please help, how can I have both series inside one chart, but adding second one does not destroy the positions of first series?
I would be happy, if it could still rescale correctly, without me having to put min and max value for axis (autoscaling, similar to first example). If it is not possible, please give me an example how to do it manually.
Full code sample in method RptFieldObject::setProperty, repository QtRPT https://qtrpt.sourceforge.io/index.php
I found the cause in my QtRpt xml template. I was setting staticChart to be false, which seems to be causing the bad scaling when multiple series are present. My template looked like this:
<TContainerField height="379" staticChart="0" type="diagram" chartType="SeriesTypeLine" ...
<graph color="rgba(255,0,0,255)" graphDS="" caption="Sensor 1">
<value x="0.00" y="37.950">
<value x="0.10" y="41.050">
<value x="0.20" y="41.300">
Which caused the QtRpt function RptFieldObject::setProperty to add following property to QChart
chart->setProperty("staticChart", e.attribute("staticChart", "1").toInt());
When setting the staticChart to true, I can not reproduce the issue anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With