##// END OF EJS Templates
Added plot area background customization to customchart example...
Miikka Heikkinen -
r2502:a1abb208b1ea
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,121 +1,131
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QLineSeries>
25 25 #include <QCategoryAxis>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 int main(int argc, char *argv[])
30 30 {
31 31 QApplication a(argc, argv);
32 32
33 33 //![1]
34 34 QLineSeries *series = new QLineSeries();
35 35 *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26);
36 36 QChart *chart = new QChart();
37 37 chart->legend()->hide();
38 38 chart->addSeries(series);
39 39 //![1]
40 40
41 41 //![2]
42 42 // Customize series
43 43 QPen pen(QRgb(0xfdb157));
44 44 pen.setWidth(5);
45 45 series->setPen(pen);
46 46
47 47 // Customize chart title
48 48 QFont font;
49 49 font.setPixelSize(18);
50 50 chart->setTitleFont(font);
51 51 chart->setTitleBrush(QBrush(Qt::white));
52 52 chart->setTitle("Customchart example");
53 53
54 54 // Customize chart background
55 55 QLinearGradient backgroundGradient;
56 56 backgroundGradient.setStart(QPointF(0, 0));
57 57 backgroundGradient.setFinalStop(QPointF(0, 1));
58 58 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
59 59 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
60 60 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
61 61 chart->setBackgroundBrush(backgroundGradient);
62
63 // Customize plot area background
64 QLinearGradient plotAreaGradient;
65 plotAreaGradient.setStart(QPointF(0, 1));
66 plotAreaGradient.setFinalStop(QPointF(1, 0));
67 plotAreaGradient.setColorAt(0.0, QRgb(0x555555));
68 plotAreaGradient.setColorAt(1.0, QRgb(0x55aa55));
69 plotAreaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
70 chart->setPlotAreaBackgroundBrush(plotAreaGradient);
71 chart->setPlotAreaBackgroundVisible(true);
62 72 //![2]
63 73
64 74 //![3]
65 75 QCategoryAxis *axisX = new QCategoryAxis();
66 76 QCategoryAxis *axisY = new QCategoryAxis();
67 77
68 78 // Customize axis label font
69 79 QFont labelsFont;
70 80 labelsFont.setPixelSize(12);
71 81 axisX->setLabelsFont(labelsFont);
72 82 axisY->setLabelsFont(labelsFont);
73 83
74 84 // Customize axis colors
75 85 QPen axisPen(QRgb(0xd18952));
76 86 axisPen.setWidth(2);
77 87 axisX->setLinePen(axisPen);
78 88 axisY->setLinePen(axisPen);
79 89
80 90 // Customize axis label colors
81 91 QBrush axisBrush(Qt::white);
82 92 axisX->setLabelsBrush(axisBrush);
83 93 axisY->setLabelsBrush(axisBrush);
84 94
85 95 // Customize grid lines and shades
86 96 axisX->setGridLineVisible(false);
87 97 axisY->setGridLineVisible(false);
88 98 axisY->setShadesPen(Qt::NoPen);
89 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
99 axisY->setShadesBrush(QBrush(QColor(0x99, 0xcc, 0xcc, 0x55)));
90 100 axisY->setShadesVisible(true);
91 101 //![3]
92 102
93 103 //![4]
94 104 axisX->append("low", 10);
95 105 axisX->append("optimal", 20);
96 106 axisX->append("high", 30);
97 107 axisX->setRange(0, 30);
98 108
99 109 axisY->append("slow", 10);
100 110 axisY->append("med", 20);
101 111 axisY->append("fast", 30);
102 112 axisY->setRange(0, 30);
103 113
104 114 chart->setAxisX(axisX, series);
105 115 chart->setAxisY(axisY, series);
106 116 //![4]
107 117
108 118 //![5]
109 119 QChartView *chartView = new QChartView(chart);
110 120 chartView->setRenderHint(QPainter::Antialiasing);
111 121 //![5]
112 122
113 123 //![6]
114 124 QMainWindow window;
115 125 window.setCentralWidget(chartView);
116 126 window.resize(400, 300);
117 127 window.show();
118 128 //![6]
119 129
120 130 return a.exec();
121 131 }
General Comments 0
You need to be logged in to leave comments. Login now