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