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