##// END OF EJS Templates
Fixed a compilation issue in axis example
Tero Ahola -
r501:6973892b62db
parent child
Show More
@@ -1,78 +1,78
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 <qchartaxis.h>
6 #include <qchartaxis.h>
7 #include <qchartaxiscategories.h>
7 #include <qchartaxiscategories.h>
8 #include <cmath>
8 #include <cmath>
9
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
11
12 #define PI 3.14159265358979
12 #define PI 3.14159265358979
13
13
14 int main(int argc, char *argv[])
14 int main(int argc, char *argv[])
15 {
15 {
16 QApplication a(argc, argv);
16 QApplication a(argc, argv);
17
17
18 QMainWindow window;
18 QMainWindow window;
19
19
20 QLineSeries* series0 = new QLineSeries();
20 QLineSeries* series0 = new QLineSeries();
21 QPen blue(Qt::blue);
21 QPen blue(Qt::blue);
22 blue.setWidth(3);
22 blue.setWidth(3);
23 series0->setPen(blue);
23 series0->setPen(blue);
24 QLineSeries* series1 = new QLineSeries();
24 QLineSeries* series1 = new QLineSeries();
25 QPen red(Qt::red);
25 QPen red(Qt::red);
26 red.setWidth(3);
26 red.setWidth(3);
27 series1->setPen(red);
27 series1->setPen(red);
28
28
29 int numPoints = 100;
29 int numPoints = 100;
30
30
31 for (int x = 0; x <= numPoints; ++x) {
31 for (int x = 0; x <= numPoints; ++x) {
32 series0->add(x, fabs(sin(PI/50*x)*100));
32 series0->add(x, fabs(sin(PI/50*x)*100));
33 series1->add(x, fabs(cos(PI/50*x)*100));
33 series1->add(x, fabs(cos(PI/50*x)*100));
34 }
34 }
35
35
36 QChartView* chartView = new QChartView(&window);
36 QChartView* chartView = new QChartView(&window);
37
37
38 chartView->setRenderHint(QPainter::Antialiasing);
38 chartView->setRenderHint(QPainter::Antialiasing);
39 chartView->setChartTitle("This is custom axis chart example");
39 chartView->setChartTitle("This is custom axis chart example");
40 chartView->addSeries(series0);
40 chartView->addSeries(series0);
41 chartView->addSeries(series1);
41 chartView->addSeries(series1);
42
42
43 QLinearGradient backgroundGradient;
43 QLinearGradient backgroundGradient;
44 backgroundGradient.setColorAt(0.0, Qt::white);
44 backgroundGradient.setColorAt(0.0, Qt::white);
45 backgroundGradient.setColorAt(1.0, QRgb(0xffff80));
45 backgroundGradient.setColorAt(1.0, QRgb(0xffff80));
46 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
46 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
47 chartView->setChartBackgroundBrush(backgroundGradient);
47 chartView->setChartBackgroundBrush(backgroundGradient);
48
48
49 QChartAxis* axisX = chartView->axisX();
49 QChartAxis* axisX = chartView->axisX();
50 axisX->setLabelsAngle(45);
50 axisX->setLabelsAngle(45);
51 axisX->setGridPen(Qt::DashLine);
51 axisX->setGridPen(Qt::DashLine);
52
52
53 QChartAxisCategories& categoriesX = axisX->categories();
53 QChartAxisCategories *categoriesX = axisX->categories();
54 categoriesX.insert(0,"low");
54 categoriesX->insert(0,"low");
55 categoriesX.insert(50,"medium");
55 categoriesX->insert(50,"medium");
56 categoriesX.insert(100,"High");
56 categoriesX->insert(100,"High");
57
57
58 axisX->setMin(-10);
58 axisX->setMin(-10);
59 axisX->setMax(2200);
59 axisX->setMax(2200);
60
60
61 QChartAxis* axisY = chartView->axisY();
61 QChartAxis* axisY = chartView->axisY();
62 axisY->setLabelsAngle(45);
62 axisY->setLabelsAngle(45);
63 axisY->setShadesBrush(Qt::yellow);
63 axisY->setShadesBrush(Qt::yellow);
64
64
65 QChartAxisCategories& categoriesY = axisY->categories();
65 QChartAxisCategories *categoriesY = axisY->categories();
66 categoriesY.insert(0,"low");
66 categoriesY->insert(0,"low");
67 categoriesY.insert(50,"medium");
67 categoriesY->insert(50,"medium");
68 categoriesY.insert(100,"High");
68 categoriesY->insert(100,"High");
69
69
70 axisY->setMin(-10);
70 axisY->setMin(-10);
71 axisY->setMax(200);
71 axisY->setMax(200);
72
72
73 window.setCentralWidget(chartView);
73 window.setCentralWidget(chartView);
74 window.resize(400, 300);
74 window.resize(400, 300);
75 window.show();
75 window.show();
76
76
77 return a.exec();
77 return a.exec();
78 }
78 }
General Comments 0
You need to be logged in to leave comments. Login now