##// END OF EJS Templates
Remove theme setting from StackedBarChart Drilldown example...
Titta Heikkala -
r2762:1774126c17aa
parent child
Show More
@@ -1,111 +1,110
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.io
5 ** For any questions to Digia, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and Digia.
12 ** agreement between you and Digia.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <QtWidgets/QApplication>
19 #include <QtWidgets/QApplication>
20 #include <QtWidgets/QMainWindow>
20 #include <QtWidgets/QMainWindow>
21 #include <QtCharts/QChartView>
21 #include <QtCharts/QChartView>
22 #include <QtCharts/QBarSet>
22 #include <QtCharts/QBarSet>
23 #include <QtCharts/QLegend>
23 #include <QtCharts/QLegend>
24 #include "drilldownseries.h"
24 #include "drilldownseries.h"
25 #include "drilldownchart.h"
25 #include "drilldownchart.h"
26
26
27 QT_CHARTS_USE_NAMESPACE
27 QT_CHARTS_USE_NAMESPACE
28
28
29 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
30 {
30 {
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32 QMainWindow window;
32 QMainWindow window;
33
33
34 //! [1]
34 //! [1]
35 DrilldownChart *drilldownChart = new DrilldownChart();
35 DrilldownChart *drilldownChart = new DrilldownChart();
36 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
37 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
36 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
38 //! [1]
37 //! [1]
39
38
40 //! [2]
39 //! [2]
41 // Define categories
40 // Define categories
42 QStringList months;
41 QStringList months;
43 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
42 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
44 QStringList weeks;
43 QStringList weeks;
45 weeks << "week 1" << "week 2" << "week 3" << "week 4";
44 weeks << "week 1" << "week 2" << "week 3" << "week 4";
46 QStringList plants;
45 QStringList plants;
47 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
46 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
48 //! [2]
47 //! [2]
49
48
50 //! [3]
49 //! [3]
51 // Create drilldown structure
50 // Create drilldown structure
52 DrilldownBarSeries *seasonSeries = new DrilldownBarSeries(months, drilldownChart);
51 DrilldownBarSeries *seasonSeries = new DrilldownBarSeries(months, drilldownChart);
53 seasonSeries->setName("Crop by month - Season");
52 seasonSeries->setName("Crop by month - Season");
54
53
55 // Each month in season series has drilldown series for weekly data
54 // Each month in season series has drilldown series for weekly data
56 for (int month = 0; month < months.count(); month++) {
55 for (int month = 0; month < months.count(); month++) {
57
56
58 // Create drilldown series for every week
57 // Create drilldown series for every week
59 DrilldownBarSeries *weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
58 DrilldownBarSeries *weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
60 seasonSeries->mapDrilldownSeries(month, weeklySeries);
59 seasonSeries->mapDrilldownSeries(month, weeklySeries);
61
60
62 // Drilling down from weekly data brings us back to season data.
61 // Drilling down from weekly data brings us back to season data.
63 for (int week = 0; week < weeks.count(); week++) {
62 for (int week = 0; week < weeks.count(); week++) {
64 weeklySeries->mapDrilldownSeries(week, seasonSeries);
63 weeklySeries->mapDrilldownSeries(week, seasonSeries);
65 weeklySeries->setName(QString("Crop by week - " + months.at(month)));
64 weeklySeries->setName(QString("Crop by week - " + months.at(month)));
66 }
65 }
67
66
68 // Use clicked signal to implement drilldown
67 // Use clicked signal to implement drilldown
69 QObject::connect(weeklySeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*)));
68 QObject::connect(weeklySeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*)));
70 }
69 }
71
70
72 // Enable drilldown from season series using clicked signal
71 // Enable drilldown from season series using clicked signal
73 QObject::connect(seasonSeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*)));
72 QObject::connect(seasonSeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*)));
74 //! [3]
73 //! [3]
75
74
76 //! [4]
75 //! [4]
77 // Fill monthly and weekly series with data
76 // Fill monthly and weekly series with data
78 foreach (QString plant, plants) {
77 foreach (QString plant, plants) {
79 QBarSet *monthlyCrop = new QBarSet(plant);
78 QBarSet *monthlyCrop = new QBarSet(plant);
80 for (int month = 0; month < months.count(); month++) {
79 for (int month = 0; month < months.count(); month++) {
81 QBarSet *weeklyCrop = new QBarSet(plant);
80 QBarSet *weeklyCrop = new QBarSet(plant);
82 for (int week = 0; week < weeks.count(); week++)
81 for (int week = 0; week < weeks.count(); week++)
83 *weeklyCrop << (qrand() % 20);
82 *weeklyCrop << (qrand() % 20);
84 // Get the drilldown series from season series and add crop to it.
83 // Get the drilldown series from season series and add crop to it.
85 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
84 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
86 *monthlyCrop << weeklyCrop->sum();
85 *monthlyCrop << weeklyCrop->sum();
87 }
86 }
88 seasonSeries->append(monthlyCrop);
87 seasonSeries->append(monthlyCrop);
89 }
88 }
90 //! [4]
89 //! [4]
91
90
92 //! [5]
91 //! [5]
93 // Show season series in initial view
92 // Show season series in initial view
94 drilldownChart->changeSeries(seasonSeries);
93 drilldownChart->changeSeries(seasonSeries);
95 drilldownChart->setTitle(seasonSeries->name());
94 drilldownChart->setTitle(seasonSeries->name());
96 //! [5]
95 //! [5]
97
96
98 //! [6]
97 //! [6]
99 drilldownChart->axisX()->setGridLineVisible(false);
98 drilldownChart->axisX()->setGridLineVisible(false);
100 drilldownChart->legend()->setVisible(true);
99 drilldownChart->legend()->setVisible(true);
101 drilldownChart->legend()->setAlignment(Qt::AlignBottom);
100 drilldownChart->legend()->setAlignment(Qt::AlignBottom);
102 //! [6]
101 //! [6]
103
102
104 QChartView *chartView = new QChartView(drilldownChart);
103 QChartView *chartView = new QChartView(drilldownChart);
105 window.setCentralWidget(chartView);
104 window.setCentralWidget(chartView);
106 window.resize(480, 300);
105 window.resize(480, 300);
107 window.show();
106 window.show();
108
107
109 return a.exec();
108 return a.exec();
110 }
109 }
111
110
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now