@@ -1,29 +1,29 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | SUBDIRS += \ |
|
3 | 3 | areachart \ |
|
4 | 4 | barchart \ |
|
5 | 5 | #chartview \ |
|
6 | 6 | customchart \ |
|
7 | 7 | #dynamiclinechart \ |
|
8 | 8 | #ekgchart \ |
|
9 | 9 | linechart \ |
|
10 | 10 | #multichart \ |
|
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 | #tablemodelchart \ |
|
21 | 21 | zoomlinechart |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 |
@@ -1,149 +1,147 | |||
|
1 | 1 | #include <QtGui/QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartglobal.h> |
|
4 | 4 | #include <qchartview.h> |
|
5 | 5 | #include <qstackedbarseries.h> |
|
6 | 6 | #include <qbarset.h> |
|
7 | 7 | #include <qchartaxis.h> |
|
8 | 8 | #include <QStringList> |
|
9 | 9 | #include <QDebug> |
|
10 | 10 | |
|
11 | 11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | 12 | |
|
13 | 13 | //! [1] |
|
14 | 14 | class DrilldownBarSeries : public QStackedBarSeries |
|
15 | 15 | { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | public: |
|
18 | 18 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {} |
|
19 | 19 | |
|
20 | 20 | void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
|
21 | 21 | { |
|
22 | 22 | mDrilldownSeries[category] = drilldownSeries; |
|
23 | 23 | } |
|
24 | 24 | |
|
25 | 25 | DrilldownBarSeries* drilldownSeries(QString category) |
|
26 | 26 | { |
|
27 | 27 | return mDrilldownSeries[category]; |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | public Q_SLOTS: |
|
31 | 31 | |
|
32 | 32 | private: |
|
33 | 33 | |
|
34 | 34 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; |
|
35 | 35 | }; |
|
36 | 36 | //! [1] |
|
37 | 37 | |
|
38 | 38 | //! [2] |
|
39 |
class DrilldownChart : public QChart |
|
|
39 | class DrilldownChart : public QChart | |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | public: |
|
43 |
explicit DrilldownChart(Q |
|
|
43 | explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) : QChart(parent, wFlags), m_currentSeries(0) {} | |
|
44 | 44 | |
|
45 | 45 | void changeSeries(QSeries* series) |
|
46 | 46 | { |
|
47 | 47 | if (m_currentSeries) |
|
48 | 48 | removeSeries(m_currentSeries); |
|
49 | 49 | m_currentSeries = series; |
|
50 | 50 | addSeries(series); |
|
51 |
set |
|
|
51 | setTitle(series->name()); | |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | public Q_SLOTS: |
|
55 |
void handle |
|
|
55 | void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button) | |
|
56 | 56 | { |
|
57 | 57 | Q_UNUSED(barset) |
|
58 | 58 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
59 | 59 | changeSeries(series->drilldownSeries(category)); |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | private: |
|
63 | 63 | QSeries* m_currentSeries; |
|
64 | 64 | }; |
|
65 | 65 | //! [2] |
|
66 | 66 | |
|
67 | 67 | int main(int argc, char *argv[]) |
|
68 | 68 | { |
|
69 | 69 | QApplication a(argc, argv); |
|
70 | 70 | QMainWindow window; |
|
71 | 71 | |
|
72 |
DrilldownChart* drilldownChart = new DrilldownChart( |
|
|
73 |
drilldownChart->set |
|
|
72 | DrilldownChart* drilldownChart = new DrilldownChart(); | |
|
73 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); | |
|
74 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); | |
|
74 | 75 | |
|
75 | 76 | //! [3] |
|
76 | 77 | // Define categories |
|
77 | 78 | QStringList months; |
|
78 | 79 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
79 | 80 | QStringList weeks; |
|
80 | 81 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
81 | 82 | QStringList plants; |
|
82 | 83 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
83 | 84 | //! [3] |
|
84 | 85 | |
|
85 | 86 | //! [4] |
|
86 | 87 | // Create drilldown structure |
|
87 | 88 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
88 | 89 | seasonSeries->setName("Crop by month - Season"); |
|
89 | 90 | |
|
90 | 91 | // Each month in season series has drilldown series for weekly data |
|
91 | 92 | foreach (QString month, months) { |
|
92 | 93 | |
|
93 | 94 | // Create drilldown series for every week |
|
94 | 95 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
95 | 96 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
96 | 97 | |
|
97 | 98 | // Drilling down from weekly data brings us back to season data. |
|
98 | 99 | foreach (QString week, weeks) { |
|
99 | 100 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
100 | 101 | weeklySeries->setName(QString("Crop by week - " + month)); |
|
101 | 102 | } |
|
102 | 103 | |
|
103 | 104 | // Use right click signal to implement drilldown |
|
104 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
105 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | // Enable drilldown from season series using right click. |
|
108 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
109 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
|
109 | 110 | //! [4] |
|
110 | 111 | |
|
111 | 112 | //! [5] |
|
112 | 113 | // Fill monthly and weekly series with data |
|
113 | 114 | foreach (QString plant, plants) { |
|
114 | 115 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
115 | 116 | foreach (QString month, months) { |
|
116 | 117 | QBarSet* weeklyCrop = new QBarSet(plant); |
|
117 |
foreach (QString week, weeks ) |
|
|
118 | foreach (QString week, weeks ) | |
|
118 | 119 | *weeklyCrop << (qrand() % 20); |
|
119 | } | |
|
120 | 120 | // Get the drilldown series from season series and add crop to it. |
|
121 |
seasonSeries->drilldownSeries(month)->a |
|
|
121 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); | |
|
122 | 122 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); |
|
123 | 123 | *monthlyCrop << weeklyCrop->total(); |
|
124 | ||
|
125 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
|
126 | 124 | } |
|
127 |
seasonSeries->a |
|
|
128 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
|
125 | seasonSeries->appendBarSet(monthlyCrop); | |
|
129 | 126 | } |
|
130 | 127 | //! [5] |
|
131 | 128 | |
|
132 | 129 | seasonSeries->setToolTipEnabled(true); |
|
133 | 130 | |
|
134 | 131 | //! [6] |
|
135 | 132 | // Show season series in initial view |
|
136 | 133 | drilldownChart->changeSeries(seasonSeries); |
|
137 |
drilldownChart->set |
|
|
134 | drilldownChart->setTitle(seasonSeries->name()); | |
|
138 | 135 | //! [6] |
|
139 | 136 | |
|
140 | 137 | drilldownChart->axisX()->setGridLineVisible(false); |
|
141 | 138 | |
|
142 | window.setCentralWidget(drilldownChart); | |
|
139 | QChartView *chartView = new QChartView(drilldownChart); | |
|
140 | window.setCentralWidget(chartView); | |
|
143 | 141 | window.resize(400, 300); |
|
144 | 142 | window.show(); |
|
145 | 143 | |
|
146 | 144 | return a.exec(); |
|
147 | 145 | } |
|
148 | 146 | |
|
149 | 147 | #include "main.moc" |
@@ -1,9 +1,7 | |||
|
1 | 1 | !include( ../examples.pri ) { |
|
2 | 2 | error( "Couldn't find the examples.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | TARGET = stackedbarchartdrilldown |
|
5 |
SOURCES += main.cpp |
|
|
6 | chartwidget.cpp | |
|
7 | HEADERS += \ | |
|
8 | chartwidget.h | |
|
5 | SOURCES += main.cpp | |
|
6 | HEADERS += | |
|
9 | 7 |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now