summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Rosa <marek.rosa@digia.com>2012-09-05 13:15:47 +0300
committerMarek Rosa <marek.rosa@digia.com>2012-09-05 13:15:47 +0300
commitea1f56016da9305fcaf161fb8f8207f23e50df34 (patch)
tree46188dae77c09d705f23682eeffffacefb711bdc
parent570404538427a02ae406bed47433d58ceefce32c (diff)
datetimeaxis example documented
-rw-r--r--doc/src/examples-datetimeaxis.qdoc37
-rw-r--r--doc/src/examples.qdoc1
-rw-r--r--examples/datetimeaxis/main.cpp21
3 files changed, 51 insertions, 8 deletions
diff --git a/doc/src/examples-datetimeaxis.qdoc b/doc/src/examples-datetimeaxis.qdoc
new file mode 100644
index 00000000..283a5c72
--- /dev/null
+++ b/doc/src/examples-datetimeaxis.qdoc
@@ -0,0 +1,37 @@
+/*!
+ \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
+
+ To present the data on the char we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart.
+
+ \snippet ../examples/datetimeaxis/main.cpp 3
+
+ Becasue 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 therfore we don't need the axis labels to contain the information about the time and the day. This is achived by setting a custom label format.
+ Please refer to QDateTime::toString() method documntation to learn about the avaiable format options.
+
+ \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
+
+*/
diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc
index 3f2547b1..26e8cbeb 100644
--- a/doc/src/examples.qdoc
+++ b/doc/src/examples.qdoc
@@ -17,6 +17,7 @@
<li><a href="examples-barchart.html">Bar chart</a></li>
<li><a href="examples-barmodelmapper.html">Bar chart from model</a></li>
<li><a href="examples-customchart.html">Custom chart</a></li>
+ <li><a href="examples-datetimeaxis.html">DateTimeAxis example</a></li>
<li><a href="examples-donutbreakdown.html">Donut breakdown chart</a></li>
<li><a href="examples-donutchart.html">Donut chart</a></li>
<li><a href="examples-horizontalbarchart.html">Horizontal bar chart</a></li>
diff --git a/examples/datetimeaxis/main.cpp b/examples/datetimeaxis/main.cpp
index ae106018..c20b3651 100644
--- a/examples/datetimeaxis/main.cpp
+++ b/examples/datetimeaxis/main.cpp
@@ -41,6 +41,8 @@ int main(int argc, char *argv[])
//![2]
// data from http://www.swpc.noaa.gov/ftpdir/weekly/RecentIndices.txt
+ // http://www.swpc.noaa.gov/ftpdir/weekly/README
+ // http://www.weather.gov/disclaimer
QFile sunSpots(":sun");
if (!sunSpots.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 1;
@@ -60,28 +62,31 @@ int main(int argc, char *argv[])
//![2]
//![3]
- QChart* chart = new QChart();
- chart->legend()->hide();
+ QChart* chart = new QChart();
chart->addSeries(series);
+ chart->legend()->hide();
chart->createDefaultAxes();
+ chart->setTitle("Sunspots count (by Space Weather Prediction Center)");
+ //![3]
+
+ //![4]
QDateTimeAxis *axisX = new QDateTimeAxis;
axisX->setTickCount(10);
axisX->setFormat("MMM yyyy");
chart->setAxisX(axisX, series);
- chart->setTitle("Sunspots count (by Space Weather Prediction Center)");
- //![3]
-
//![4]
+
+ //![5]
QChartView* chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
- //![4]
-
//![5]
+
+ //![6]
QMainWindow window;
window.setCentralWidget(chartView);
window.resize(800, 600);
window.show();
- //![5]
+ //![6]
return a.exec();
}