@@ -1,9 +1,26 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example example/linechart |
|
2 | \example example/linechart | |
3 | \title LineChart Example |
|
3 | \title LineChart Example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 | The example shows how to create simple line chart. |
|
6 | The example shows how to create simple line chart. | |
7 |
|
7 | |||
8 | ... |
|
8 | \image linechart.png | |
|
9 | ||||
|
10 | To create line charts, QLineSeries instance is needed. Here we create two line series and we set the color and width of line. | |||
|
11 | ||||
|
12 | \snippet ../example/linechart/main.cpp 1 | |||
|
13 | ||||
|
14 | We add data to be shown to both series. | |||
|
15 | ||||
|
16 | \snippet ../example/linechart/main.cpp 2 | |||
|
17 | ||||
|
18 | In the end we create QChartView instance, set title, set anti-aliasing and add both series. | |||
|
19 | ||||
|
20 | \snippet ../example/linechart/main.cpp 3 | |||
|
21 | ||||
|
22 | Chart is ready to be shown. | |||
|
23 | ||||
|
24 | \snippet ../example/linechart/main.cpp 4 | |||
|
25 | ||||
9 | */ No newline at end of file |
|
26 | */ |
@@ -1,56 +1,57 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlineseries.h> |
|
4 | #include <qlineseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | int main(int argc, char *argv[]) |
|
10 | int main(int argc, char *argv[]) | |
11 | { |
|
11 | { | |
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | QMainWindow window; |
|
|||
15 |
|
||||
16 | //![1] |
|
14 | //![1] | |
17 |
|
15 | |||
18 | QLineSeries* series0 = new QLineSeries(); |
|
16 | QLineSeries* series0 = new QLineSeries(); | |
19 | QPen blue(Qt::blue); |
|
17 | QPen blue(Qt::blue); | |
20 | blue.setWidth(3); |
|
18 | blue.setWidth(3); | |
21 | series0->setPen(blue); |
|
19 | series0->setPen(blue); | |
22 |
|
20 | |||
23 | QLineSeries* series1 = new QLineSeries(); |
|
21 | QLineSeries* series1 = new QLineSeries(); | |
24 | QPen red(Qt::red); |
|
22 | QPen red(Qt::red); | |
25 | red.setWidth(3); |
|
23 | red.setWidth(3); | |
26 | series1->setPen(red); |
|
24 | series1->setPen(red); | |
27 | //![1] |
|
25 | //![1] | |
28 |
|
26 | |||
29 | //![2] |
|
27 | //![2] | |
30 | series0->add(0, 6); |
|
28 | series0->add(0, 6); | |
31 | series0->add(2, 4); |
|
29 | series0->add(2, 4); | |
32 | series0->add(3, 8); |
|
30 | series0->add(3, 8); | |
33 | series0->add(7, 4); |
|
31 | series0->add(7, 4); | |
34 | series0->add(10,5); |
|
32 | series0->add(10,5); | |
35 |
|
33 | |||
36 | series1->add(1, 1); |
|
34 | series1->add(1, 1); | |
37 | series1->add(3, 3); |
|
35 | series1->add(3, 3); | |
38 | series1->add(7, 6); |
|
36 | series1->add(7, 6); | |
39 | series1->add(8, 3); |
|
37 | series1->add(8, 3); | |
40 | series1->add(10,2); |
|
38 | series1->add(10,2); | |
41 | //![2] |
|
39 | //![2] | |
42 | //![3] |
|
40 | //![3] | |
|
41 | QMainWindow window; | |||
43 | QChartView* chartView = new QChartView(&window); |
|
42 | QChartView* chartView = new QChartView(&window); | |
44 |
|
43 | |||
45 | chartView->setRenderHint(QPainter::Antialiasing); |
|
|||
46 | chartView->setChartTitle("Basic line chart example"); |
|
44 | chartView->setChartTitle("Basic line chart example"); | |
|
45 | chartView->setRenderHint(QPainter::Antialiasing); | |||
|
46 | ||||
47 | chartView->addSeries(series0); |
|
47 | chartView->addSeries(series0); | |
48 | chartView->addSeries(series1); |
|
48 | chartView->addSeries(series1); | |
49 | //![3] |
|
49 | //![3] | |
50 |
|
50 | //![4] | ||
51 | window.setCentralWidget(chartView); |
|
51 | window.setCentralWidget(chartView); | |
52 | window.resize(400, 300); |
|
52 | window.resize(400, 300); | |
53 | window.show(); |
|
53 | window.show(); | |
|
54 | //![4] | |||
54 |
|
55 | |||
55 | return a.exec(); |
|
56 | return a.exec(); | |
56 | } |
|
57 | } |
General Comments 0
You need to be logged in to leave comments.
Login now