@@ -1,62 +1,67 | |||||
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->setChartTitle("This is custom axis chart example"); |
|
38 | chartView->setChartTitle("This is custom axis chart example"); | |
39 | chartView->addSeries(series0); |
|
39 | chartView->addSeries(series0); | |
40 | chartView->addSeries(series1); |
|
40 | chartView->addSeries(series1); | |
41 |
|
41 | |||
42 |
|
||||
43 | QLinearGradient backgroundGradient; |
|
42 | QLinearGradient backgroundGradient; | |
44 | backgroundGradient.setColorAt(0.0, Qt::white); |
|
43 | backgroundGradient.setColorAt(0.0, Qt::white); | |
45 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); |
|
44 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); | |
46 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
45 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
47 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
46 | chartView->setChartBackgroundBrush(backgroundGradient); | |
48 |
|
47 | |||
49 |
QChartAxis axis = chartView-> |
|
48 | QChartAxis* axisX = chartView->axisX(); | |
50 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); |
|
49 | axisX->setLabelsAngle(45); | |
51 |
axis |
|
50 | axisX->setGridPen(Qt::DashLine); | |
|
51 | axisX->addAxisTickLabel(0,"low"); | |||
|
52 | axisX->addAxisTickLabel(50,"medium"); | |||
|
53 | axisX->addAxisTickLabel(100,"High"); | |||
52 |
|
54 | |||
53 | chartView->setDefaultAxisX(axis); |
|
55 | QChartAxis* axisY = chartView->axisY(); | |
54 | axis.setShadesBrush(Qt::yellow); |
|
56 | axisY->setLabelsAngle(45); | |
55 | chartView->setDefaultAxisY(axis); |
|
57 | axisY->setShadesBrush(Qt::yellow); | |
|
58 | axisY->addAxisTickLabel(0,"low"); | |||
|
59 | axisY->addAxisTickLabel(50,"medium"); | |||
|
60 | axisY->addAxisTickLabel(100,"High"); | |||
56 |
|
61 | |||
57 | window.setCentralWidget(chartView); |
|
62 | window.setCentralWidget(chartView); | |
58 | window.resize(400, 300); |
|
63 | window.resize(400, 300); | |
59 | window.show(); |
|
64 | window.show(); | |
60 |
|
65 | |||
61 | return a.exec(); |
|
66 | return a.exec(); | |
62 | } |
|
67 | } |
General Comments 0
You need to be logged in to leave comments.
Login now