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