##// END OF EJS Templates
logvalueaxis and multiaxis examples documented
Marek Rosa -
r2374:01d2a7083c00
parent child
Show More
@@ -0,0 +1,30
1 /*!
2 \example examples/logvalueaxis
3 \title Logarithmic axis example
4 \subtitle
5
6 The example shows how to use QLogValueAxis.
7
8 \image examples_logvalueaxis.png
9
10 Create QLineSeries instance and add some data to it.
11
12 \snippet ../examples/logvalueaxis/main.cpp 1
13
14 To present the data on the char we need QChart instance. Add the series to it, hide the legend and set the title of the chart.
15
16 \snippet ../examples/logvalueaxis/main.cpp 2
17
18 Create the axes. Add them to the chart and attach to the series.
19
20 \snippet ../examples/logvalueaxis/main.cpp 3
21
22 Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer.
23
24 \snippet ../examples/logvalueaxis/main.cpp 4
25
26 Chart is ready to be shown.
27
28 \snippet ../examples/logvalueaxis/main.cpp 5
29
30 */
@@ -0,0 +1,36
1 /*!
2 \example examples/multiaxis
3 \title Multiple axes example
4 \subtitle
5
6 The example shows how to create simple chart with two vertical axes. One for each series.
7
8 \image examples_multiaxis.png
9
10 Create QChart instance, hide the legend of the chart and set its title.
11
12 \snippet ../examples/multiaxis/main.cpp 1
13
14 Create a QValueAxis instance that will be used as a horizontal axis by both series and add it the bottom of the chart.
15 Axis can be sharted between many series, but each series can have only one vertical and horizontal axis.
16
17 \snippet ../examples/multiaxis/main.cpp 2
18
19 Create the first series, add the data to it, finally add the series to the chart. Instantiate its own Y-axis, add it to the chart then attach both the common X-axis and the series specific Y-axis.
20 In this example the color of the axis line is set to be the same as the color of the series to make it possible to distinguish which axis is attached to which series.
21
22 \snippet ../examples/multiaxis/main.cpp 3
23
24 Similarly prepare another series. This time different axis type is used. Additionally grid lines color is also set to be the same as the color of the series.
25
26 \snippet ../examples/multiaxis/main.cpp 4
27
28 Create a QChartView object with QChart as a parameter. Enanle Antialiasing to have the rendered splines look nicer.
29
30 \snippet ../examples/multiaxis/main.cpp 5
31
32 Chart is ready to be shown.
33
34 \snippet ../examples/multiaxis/main.cpp 6
35
36 */
@@ -70,11 +70,20
70 </tr>
70 </tr>
71
71
72 <tr>
72 <tr>
73 <td><a href="examples-logvalueaxis.html">Logarythmic axis</a></td>
73 <td><a href="examples-modeldata.html">Model Data</a></td>
74 <td><a href="examples-modeldata.html">Model Data</a></td>
74 <td><a href="examples-percentbarchart.html">Percent Bar Chart</a></td>
75 </tr>
75 </tr>
76 <tr>
76 <tr>
77 <td><a href="examples-logvalueaxis.html"><img src="images/examples_logvalueaxis.png" width="300" alt="Logarythmix axis" /></a></td>
77 <td><a href="examples-modeldata.html"><img src="images/examples_modeldata.png" width="300" alt="Model Data" /></a></td>
78 <td><a href="examples-modeldata.html"><img src="images/examples_modeldata.png" width="300" alt="Model Data" /></a></td>
79 </tr>
80
81 <tr>
82 <td><a href="examples-multiaxis.html">Multiple axes</a></td>
83 <td><a href="examples-percentbarchart.html">Percent Bar Chart</a></td>
84 </tr>
85 <tr>
86 <td><a href="examples-multiaxis.html"><img src="images/examples_multiaxis.png" width="300" alt="Multiple axes" /></a></td>
78 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="300" alt="Percent Bar Chart" /></a></td>
87 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="300" alt="Percent Bar Chart" /></a></td>
79 </tr>
88 </tr>
80
89
@@ -36,14 +36,14 int main(int argc, char *argv[])
36 *series << QPointF(1, 1) << QPointF(2, 73) << QPointF(3, 268) << QPointF(4, 17) << QPointF(5, 4325) << QPointF(6, 723);
36 *series << QPointF(1, 1) << QPointF(2, 73) << QPointF(3, 268) << QPointF(4, 17) << QPointF(5, 4325) << QPointF(6, 723);
37 //![1]
37 //![1]
38
38
39 //![3]
39 //![2]
40 QChart *chart = new QChart();
40 QChart *chart = new QChart();
41 chart->addSeries(series);
41 chart->addSeries(series);
42 chart->legend()->hide();
42 chart->legend()->hide();
43 chart->setTitle("QLogValueAxis chart example");
43 chart->setTitle("Logarithmic axis example");
44 //![3]
44 //![2]
45
45
46 //![4]
46 //![3]
47 QValueAxis *axisX = new QValueAxis;
47 QValueAxis *axisX = new QValueAxis;
48 axisX->setTitleText("Data point");
48 axisX->setTitleText("Data point");
49 axisX->setTickCount(6);
49 axisX->setTickCount(6);
@@ -54,14 +54,15 int main(int argc, char *argv[])
54 QLogValueAxis *axisY = new QLogValueAxis;
54 QLogValueAxis *axisY = new QLogValueAxis;
55 axisY->setLabelFormat("%g");
55 axisY->setLabelFormat("%g");
56 axisY->setTitleText("Values");
56 axisY->setTitleText("Values");
57 axisY->setBase(8);
57 chart->addAxis(axisY, Qt::AlignLeft);
58 chart->addAxis(axisY, Qt::AlignLeft);
58 series->attachAxis(axisY);
59 series->attachAxis(axisY);
59 //![4]
60 //![3]
60
61
61 //![5]
62 //![4]
62 QChartView *chartView = new QChartView(chart);
63 QChartView *chartView = new QChartView(chart);
63 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
64 //![5]
65 //![4]
65
66
66 //![6]
67 //![6]
67 QMainWindow window;
68 QMainWindow window;
@@ -33,10 +33,18 int main(int argc, char *argv[])
33 QApplication a(argc, argv);
33 QApplication a(argc, argv);
34
34
35 //![1]
35 //![1]
36 QChart *chart = new QChart();
36 QChart *chart = new QChart();
37 chart->legend()->hide();
38 chart->setTitle("Multiaxis chart example");
39 //![1]
40
41 //![2]
37 QValueAxis *axisX = new QValueAxis;
42 QValueAxis *axisX = new QValueAxis;
38 axisX->setTickCount(10);
43 axisX->setTickCount(10);
44 chart->addAxis(axisX, Qt::AlignBottom);
45 //![2]
39
46
47 //![3]
40 QSplineSeries *series = new QSplineSeries;
48 QSplineSeries *series = new QSplineSeries;
41 *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5);
49 *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5);
42 chart->addSeries(series);
50 chart->addSeries(series);
@@ -44,11 +52,12 int main(int argc, char *argv[])
44 QValueAxis *axisY = new QValueAxis;
52 QValueAxis *axisY = new QValueAxis;
45 axisY->setLinePenColor(series->pen().color());
53 axisY->setLinePenColor(series->pen().color());
46
54
47 chart->addAxis(axisX, Qt::AlignBottom);
48 chart->addAxis(axisY, Qt::AlignLeft);
55 chart->addAxis(axisY, Qt::AlignLeft);
49 series->attachAxis(axisX);
56 series->attachAxis(axisX);
50 series->attachAxis(axisY);
57 series->attachAxis(axisY);
58 //![3]
51
59
60 //![4]
52 series = new QSplineSeries;
61 series = new QSplineSeries;
53 *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5)
62 *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5)
54 << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17);
63 << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17);
@@ -64,26 +73,19 int main(int argc, char *argv[])
64 chart->addAxis(axisY3, Qt::AlignRight);
73 chart->addAxis(axisY3, Qt::AlignRight);
65 series->attachAxis(axisX);
74 series->attachAxis(axisX);
66 series->attachAxis(axisY3);
75 series->attachAxis(axisY3);
67
68 //![2]
69
70 //![3]
71 chart->legend()->hide();
72 chart->setTitle("Multiaxis chart example");
73 //![3]
74
75 //![4]
76 //![4]
77
78 //![5]
76 QChartView *chartView = new QChartView(chart);
79 QChartView *chartView = new QChartView(chart);
77 chartView->setRenderHint(QPainter::Antialiasing);
80 chartView->setRenderHint(QPainter::Antialiasing);
78 //![4]
79
80
81 //![5]
81 //![5]
82
83 //![6]
82 QMainWindow window;
84 QMainWindow window;
83 window.setCentralWidget(chartView);
85 window.setCentralWidget(chartView);
84 window.resize(800, 600);
86 window.resize(800, 600);
85 window.show();
87 window.show();
86 //![5]
88 //![6]
87
89
88 return a.exec();
90 return a.exec();
89 }
91 }
General Comments 0
You need to be logged in to leave comments. Login now