##// END OF EJS Templates
Changed comma to full stop...
Changed comma to full stop Change-Id: If0023777995c99855fe731568e8c3e8abd5d1ba5 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2456:4278a56d8f51
r2535:3c82f10df041
Show More
examples-datetimeaxis.qdoc
37 lines | 1.9 KiB | text/plain | TextLexer
/ doc / src / examples-datetimeaxis.qdoc
Marek Rosa
datetimeaxis example documented
r1986 /*!
\example examples/datetimeaxis
\title DateTimeAxis Example
\subtitle
The example shows how to use QLineChart with QDateTimeAxis.
\image examples_datetimeaxis.png
To create line chart, QLineSeries instance is needed. Let's create one.
\snippet ../examples/datetimeaxis/main.cpp 1
On the charts we will present how the number of sun spots changes in time. The data (by Space Weather Prediction Center) is read from a text file.
In the snippet below notice how QDateTime::toMSecsSinceEpoch method is used to convert the QDateTime object into a number that can be passed to QLineSeries append method.
\snippet ../examples/datetimeaxis/main.cpp 2
Mika Salmela
Fix for typos on documentation.
r2456 To present the data on the chart we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart.
Marek Rosa
datetimeaxis example documented
r1986
\snippet ../examples/datetimeaxis/main.cpp 3
Mika Salmela
Fix for typos on documentation.
r2456 Because we use QLineSeries calling createDefaultAxes will create QValueAxis both as X and Y axis. To use QDateTimeAxis we need to set it manually to the chart.
First the instance of QDateTimeAxis is created, then the number of ticks that are to be shown is set. The number of sun spots is provided as an average for the month therefore we don't need the axis labels to contain the information about the time and the day. This is achieved by setting a custom label format.
Please refer to QDateTime::toString() method documentation to learn about the available format options.
Marek Rosa
datetimeaxis example documented
r1986
\snippet ../examples/datetimeaxis/main.cpp 4
Then we create a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
\snippet ../examples/datetimeaxis/main.cpp 5
Chart is ready to be shown.
\snippet ../examples/datetimeaxis/main.cpp 6
*/