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