@@ -1,56 +1,56 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <qchartaxis.h> |
|
6 | #include <qchartaxis.h> | |
7 | #include <cmath> |
|
7 | #include <cmath> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | #define PI 3.14159265358979 |
|
11 | #define PI 3.14159265358979 | |
12 |
|
12 | |||
13 | int main(int argc, char *argv[]) |
|
13 | int main(int argc, char *argv[]) | |
14 | { |
|
14 | { | |
15 | QApplication a(argc, argv); |
|
15 | QApplication a(argc, argv); | |
16 |
|
16 | |||
17 | QMainWindow window; |
|
17 | QMainWindow window; | |
18 |
|
18 | |||
19 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
19 | QLineChartSeries* series0 = new QLineChartSeries(); | |
20 | QPen blue(Qt::blue); |
|
20 | QPen blue(Qt::blue); | |
21 | blue.setWidth(3); |
|
21 | blue.setWidth(3); | |
22 | series0->setPen(blue); |
|
22 | series0->setPen(blue); | |
23 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
23 | QLineChartSeries* series1 = new QLineChartSeries(); | |
24 | QPen red(Qt::red); |
|
24 | QPen red(Qt::red); | |
25 | red.setWidth(3); |
|
25 | red.setWidth(3); | |
26 | series1->setPen(red); |
|
26 | series1->setPen(red); | |
27 |
|
27 | |||
28 | int numPoints = 100; |
|
28 | int numPoints = 100; | |
29 |
|
29 | |||
30 | for (int x = 0; x <= numPoints; ++x) { |
|
30 | for (int x = 0; x <= numPoints; ++x) { | |
31 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
31 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
32 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
32 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QChartView* chartView = new QChartView(&window); |
|
35 | QChartView* chartView = new QChartView(&window); | |
36 |
|
36 | |||
37 | chartView->setRenderHint(QPainter::Antialiasing); |
|
37 | chartView->setRenderHint(QPainter::Antialiasing); | |
38 | chartView->setTitle("Basic line chart example"); |
|
38 | chartView->setTitle("Basic line chart example"); | |
39 | chartView->addSeries(series0); |
|
39 | chartView->addSeries(series0); | |
40 | chartView->addSeries(series1); |
|
40 | chartView->addSeries(series1); | |
41 | chartView->setChartBackgroundBrush(Qt::white); |
|
41 | chartView->setChartBackgroundBrush(Qt::white); | |
42 |
|
42 | |||
43 | QChartAxis axis = chartView->defaultAxisX(); |
|
43 | QChartAxis axis = chartView->defaultAxisX(); | |
44 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); |
|
44 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |
45 | axis.setGridPen(Qt::DashLine); |
|
45 | axis.setGridPen(Qt::DashLine); | |
46 |
|
46 | |||
47 | chartView->setDefaultAxisX(axis); |
|
47 | chartView->setDefaultAxisX(axis); | |
48 | axis.setShadesBrush(Qt::gray); |
|
48 | axis.setShadesBrush(Qt::lightGray); | |
49 | chartView->setDefaultAxisY(axis); |
|
49 | chartView->setDefaultAxisY(axis); | |
50 |
|
50 | |||
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 |
|
54 | |||
55 | return a.exec(); |
|
55 | return a.exec(); | |
56 | } |
|
56 | } |
General Comments 0
You need to be logged in to leave comments.
Login now