##// END OF EJS Templates
Customchart example updated
Marek Rosa -
r1647:35c35dbacb1e
parent child
Show More
@@ -1,26 +1,26
1 1 /*!
2 2 \example examples/customchart
3 3 \title Custom chart example
4 4 \subtitle
5 5
6 6 This example shows how to customize the appearance of the different elements on a chart.
7 7 \image examples_customchart.png
8 8
9 9 We begin by creating a simple line series and a chart object.
10 10 \snippet ../examples/customchart/main.cpp 1
11 11
12 12 Let the customization begin. First we customize the series and the chart's title and background.
13 13 \snippet ../examples/customchart/main.cpp 2
14 14
15 15 Then we customize the axes.
16 16 \snippet ../examples/customchart/main.cpp 3
17 17
18 And the axis label values and ranges.
18 And the axis label values and ranges. Once the axes are ready we set them to be used by the chart.
19 19 \snippet ../examples/customchart/main.cpp 4
20 20
21 21 Finally we create a view containing the chart.
22 22 \snippet ../examples/customchart/main.cpp 5
23 23
24 24 Now we are ready to show the chart on a main window.
25 25 \snippet ../examples/customchart/main.cpp 6
26 26 */
@@ -1,124 +1,119
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 <QValuesAxis>
26 #include <QBarCategoriesAxis>
26 27
27 28 QTCOMMERCIALCHART_USE_NAMESPACE
28 29
29 30 int main(int argc, char *argv[])
30 31 {
31 32 QApplication a(argc, argv);
32 33
33 34 //![1]
34 35 QLineSeries* series = new QLineSeries();
35 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
36 *series << QPointF(0, 6) << QPointF(0.5, 4) << QPointF(1, 8) << QPointF(1.5, 4) << QPointF(2, 3);
36 37 QChart* chart = new QChart();
37 38 chart->legend()->hide();
38 39 chart->addSeries(series);
39 chart->createDefaultAxes();
40 40 //![1]
41 41
42 42 //![2]
43 43 // Customize series
44 44 QPen pen(QRgb(0xfdb157));
45 45 pen.setWidth(5);
46 46 series->setPen(pen);
47 47
48 48 // Customize chart title
49 49 QFont font;
50 50 font.setPixelSize(18);
51 51 chart->setTitleFont(font);
52 52 chart->setTitleBrush(QBrush(Qt::white));
53 53 chart->setTitle("Customchart example");
54 54
55 55 // Customize chart background
56 56 QLinearGradient backgroundGradient;
57 57 backgroundGradient.setStart(QPointF(0,0));
58 58 backgroundGradient.setFinalStop(QPointF(0,1));
59 59 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
60 60 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
61 61 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
62 62 chart->setBackgroundBrush(backgroundGradient);
63 63 //![2]
64 64
65 65 //![3]
66 QValuesAxis* axisX = qobject_cast<QValuesAxis *>(chart->axisX());
67 QValuesAxis* axisY = qobject_cast<QValuesAxis *>(chart->axisY());
66 QBarCategoriesAxis* axisX = new QBarCategoriesAxis;
67 QValuesAxis* axisY = new QValuesAxis;
68 68
69 69 // Customize axis label font
70 70 QFont labelsFont;
71 71 labelsFont.setPixelSize(12);
72 72 axisX->setLabelsFont(labelsFont);
73 73 axisY->setLabelsFont(labelsFont);
74 74
75 75 // Customize axis colors
76 76 QPen axisPen(QRgb(0xd18952));
77 77 axisPen.setWidth(2);
78 78 axisX->setAxisPen(axisPen);
79 79 axisY->setAxisPen(axisPen);
80 80
81 81 // Customize axis label colors
82 82 QBrush axisBrush(Qt::white);
83 83 axisX->setLabelsBrush(axisBrush);
84 84 axisY->setLabelsBrush(axisBrush);
85 85
86 86 // Customize grid lines and shades
87 87 axisX->setGridLineVisible(false);
88 88 axisY->setGridLineVisible(false);
89 89 axisY->setShadesPen(Qt::NoPen);
90 90 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
91 91 axisY->setShadesVisible(true);
92 92 //![3]
93 93
94 94 //![4]
95 // QAxisCategories* categoriesX = chart->axisX()->categories();
96 // categoriesX->insert(1,"low");
97 // categoriesX->insert(5,"optimal");
98 // categoriesX->insert(10,"high");
99
100 // QAxisCategories* categoriesY = chart->axisY()->categories();
101 // categoriesY->insert(1,"slow");
102 // categoriesY->insert(5,"med");
103 // categoriesY->insert(10,"fast");
104
105 axisX->setRange(0,10);
106 axisX->setTicksCount(4);
95 axisX->append("low");
96 axisX->append("optimal");
97 axisX->append("high");
98
99 axisX->setRange("low","high");
107 100 axisY->setRange(0,10);
108 101 axisY->setTicksCount(4);
102 chart->setAxisX(axisX, series);
103 chart->setAxisY(axisY, series);
109 104 //![4]
110 105
111 106 //![5]
112 107 QChartView* chartView = new QChartView(chart);
113 108 chartView->setRenderHint(QPainter::Antialiasing);
114 109 //![5]
115 110
116 111 //![6]
117 112 QMainWindow window;
118 113 window.setCentralWidget(chartView);
119 114 window.resize(400, 300);
120 115 window.show();
121 116 //![6]
122 117
123 118 return a.exec();
124 119 }
General Comments 0
You need to be logged in to leave comments. Login now