##// END OF EJS Templates
Customchart partially fixed (no categories on axes)
Marek Rosa -
r1631:3d0288033004
parent child
Show More
@@ -1,122 +1,124
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25 #include <QValuesAxis>
25
26
26 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
27
28
28 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
29 {
30 {
30 QApplication a(argc, argv);
31 QApplication a(argc, argv);
31
32
32 //![1]
33 //![1]
33 QLineSeries* series = new QLineSeries();
34 QLineSeries* series = new QLineSeries();
34 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
35 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
35 QChart* chart = new QChart();
36 QChart* chart = new QChart();
36 chart->legend()->hide();
37 chart->legend()->hide();
37 chart->addSeries(series);
38 chart->addSeries(series);
39 chart->createDefaultAxes();
38 //![1]
40 //![1]
39
41
40 //![2]
42 //![2]
41 // Customize series
43 // Customize series
42 QPen pen(QRgb(0xfdb157));
44 QPen pen(QRgb(0xfdb157));
43 pen.setWidth(5);
45 pen.setWidth(5);
44 series->setPen(pen);
46 series->setPen(pen);
45
47
46 // Customize chart title
48 // Customize chart title
47 QFont font;
49 QFont font;
48 font.setPixelSize(18);
50 font.setPixelSize(18);
49 chart->setTitleFont(font);
51 chart->setTitleFont(font);
50 chart->setTitleBrush(QBrush(Qt::white));
52 chart->setTitleBrush(QBrush(Qt::white));
51 chart->setTitle("Customchart example");
53 chart->setTitle("Customchart example");
52
54
53 // Customize chart background
55 // Customize chart background
54 QLinearGradient backgroundGradient;
56 QLinearGradient backgroundGradient;
55 backgroundGradient.setStart(QPointF(0,0));
57 backgroundGradient.setStart(QPointF(0,0));
56 backgroundGradient.setFinalStop(QPointF(0,1));
58 backgroundGradient.setFinalStop(QPointF(0,1));
57 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
59 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
58 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
60 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
59 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
61 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
60 chart->setBackgroundBrush(backgroundGradient);
62 chart->setBackgroundBrush(backgroundGradient);
61 //![2]
63 //![2]
62
64
63 //![3]
65 //![3]
64 QAxis* axisX = chart->axisX();
66 QValuesAxis* axisX = qobject_cast<QValuesAxis *>(chart->axisX());
65 QAxis* axisY = chart->axisY();
67 QValuesAxis* axisY = qobject_cast<QValuesAxis *>(chart->axisY());
66
68
67 // Customize axis label font
69 // Customize axis label font
68 QFont labelsFont;
70 QFont labelsFont;
69 labelsFont.setPixelSize(12);
71 labelsFont.setPixelSize(12);
70 axisX->setLabelsFont(labelsFont);
72 axisX->setLabelsFont(labelsFont);
71 axisY->setLabelsFont(labelsFont);
73 axisY->setLabelsFont(labelsFont);
72
74
73 // Customize axis colors
75 // Customize axis colors
74 QPen axisPen(QRgb(0xd18952));
76 QPen axisPen(QRgb(0xd18952));
75 axisPen.setWidth(2);
77 axisPen.setWidth(2);
76 axisX->setAxisPen(axisPen);
78 axisX->setAxisPen(axisPen);
77 axisY->setAxisPen(axisPen);
79 axisY->setAxisPen(axisPen);
78
80
79 // Customize axis label colors
81 // Customize axis label colors
80 QBrush axisBrush(Qt::white);
82 QBrush axisBrush(Qt::white);
81 axisX->setLabelsBrush(axisBrush);
83 axisX->setLabelsBrush(axisBrush);
82 axisY->setLabelsBrush(axisBrush);
84 axisY->setLabelsBrush(axisBrush);
83
85
84 // Customize grid lines and shades
86 // Customize grid lines and shades
85 axisX->setGridLineVisible(false);
87 axisX->setGridLineVisible(false);
86 axisY->setGridLineVisible(false);
88 axisY->setGridLineVisible(false);
87 axisY->setShadesPen(Qt::NoPen);
89 axisY->setShadesPen(Qt::NoPen);
88 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
90 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
89 axisY->setShadesVisible(true);
91 axisY->setShadesVisible(true);
90 //![3]
92 //![3]
91
93
92 //![4]
94 //![4]
93 QAxisCategories* categoriesX = chart->axisX()->categories();
95 // QAxisCategories* categoriesX = chart->axisX()->categories();
94 categoriesX->insert(1,"low");
96 // categoriesX->insert(1,"low");
95 categoriesX->insert(5,"optimal");
97 // categoriesX->insert(5,"optimal");
96 categoriesX->insert(10,"high");
98 // categoriesX->insert(10,"high");
97
99
98 QAxisCategories* categoriesY = chart->axisY()->categories();
100 // QAxisCategories* categoriesY = chart->axisY()->categories();
99 categoriesY->insert(1,"slow");
101 // categoriesY->insert(1,"slow");
100 categoriesY->insert(5,"med");
102 // categoriesY->insert(5,"med");
101 categoriesY->insert(10,"fast");
103 // categoriesY->insert(10,"fast");
102
104
103 axisX->setRange(0,10);
105 axisX->setRange(0,10);
104 axisX->setTicksCount(4);
106 axisX->setTicksCount(4);
105 axisY->setRange(0,10);
107 axisY->setRange(0,10);
106 axisY->setTicksCount(4);
108 axisY->setTicksCount(4);
107 //![4]
109 //![4]
108
110
109 //![5]
111 //![5]
110 QChartView* chartView = new QChartView(chart);
112 QChartView* chartView = new QChartView(chart);
111 chartView->setRenderHint(QPainter::Antialiasing);
113 chartView->setRenderHint(QPainter::Antialiasing);
112 //![5]
114 //![5]
113
115
114 //![6]
116 //![6]
115 QMainWindow window;
117 QMainWindow window;
116 window.setCentralWidget(chartView);
118 window.setCentralWidget(chartView);
117 window.resize(400, 300);
119 window.resize(400, 300);
118 window.show();
120 window.show();
119 //![6]
121 //![6]
120
122
121 return a.exec();
123 return a.exec();
122 }
124 }
@@ -1,25 +1,25
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += \
7 SUBDIRS += \
8 areachart \
8 areachart \
9 #customchart \
9 customchart \
10 linechart \
10 linechart \
11 percentbarchart \
11 percentbarchart \
12 piechart \
12 piechart \
13 piechartdrilldown \
13 piechartdrilldown \
14 presenterchart \
14 presenterchart \
15 scatterchart \
15 scatterchart \
16 scatterinteractions \
16 scatterinteractions \
17 splinechart \
17 splinechart \
18 stackedbarchart \
18 stackedbarchart \
19 stackedbarchartdrilldown \
19 stackedbarchartdrilldown \
20 zoomlinechart \
20 zoomlinechart \
21 modeldata \
21 modeldata \
22 barchart \
22 barchart \
23 legend \
23 legend \
24 barmodelmapper \
24 barmodelmapper \
25 qmlpiechart
25 qmlpiechart
General Comments 0
You need to be logged in to leave comments. Login now