##// END OF EJS Templates
stacked bar drilldown example documentation update
sauimone -
r1415:3a9150ae63dc
parent child
Show More
@@ -11,32 +11,35
11 11 Mouse button clicked on a month, shows the harvest from that month:
12 12 \image examples_stackedbarchartdrilldown2.png
13 13
14 Here we define a drilldown series, which adds mapping for categories to other drilldown series.
15 Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(QString category) function.
14 First we define a drilldown series class, which adds categories to stacked bar series and mapping for categories to other drilldown series.
15 Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(int category) function.
16 16
17 \snippet ../examples/stackedbarchartdrilldown/main.cpp 1
17 \snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1
18 18
19 To enable drilldown we create own view, which implements handler for right click. All QBarSeries derived classes send out rightClicked(QBarSet*, QString) signal when series is clicked with right mouse button. The parameters QBarSet and QString contain the pointer to clicked bar set and name of category, where click occurred.
19 Next we define our own drilldown chart, which implements handler for mouse click. All QBarSeries derived classes send out clicked(QBarSet*, int) signal when series is clicked with mouse. The parameter QBarSet contains pointer to clicked bar set and parameter int contains the index of clicked category.
20 20
21 In our DrilldownChart we implement handler, which selects the drilldown chart with the category.
21 \snippet ../examples/stackedbarchartdrilldown/drilldownchart.h 1
22 22
23 \snippet ../examples/stackedbarchartdrilldown/main.cpp 2
23 Now we have our drilldown classes and we can start using them.
24 First create the chart.
25
26 \snippet ../examples/stackedbarchartdrilldown/main.cpp 1
24 27
25 Here we define data, which we use to construct the chart.
28 We define categories, from wich the drilldown series will be constructed.
26 29
27 \snippet ../examples/stackedbarchartdrilldown/main.cpp 3
30 \snippet ../examples/stackedbarchartdrilldown/main.cpp 2
28 31
29 32 To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series, called weeklySeries which contains more detailed data for that month.
30 33 In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do this we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries.
31 To make mapping work, we connect the rightClicked signals from our series to the drilldownChart.
34 To make mapping work, we connect the clicked signals from our series to the drilldownChart.
32 35
33 \snippet ../examples/stackedbarchartdrilldown/main.cpp 4
36 \snippet ../examples/stackedbarchartdrilldown/main.cpp 3
34 37
35 When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops. To enable floating values, we connect the clicked signal to toggle the value of corresponding set.
38 When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops and is set as value to monthly series.
36 39
37 \snippet ../examples/stackedbarchartdrilldown/main.cpp 5
40 \snippet ../examples/stackedbarchartdrilldown/main.cpp 4
38 41
39 42 Here we set the chart to show top level series initially.
40 43
41 \snippet ../examples/stackedbarchartdrilldown/main.cpp 6
44 \snippet ../examples/stackedbarchartdrilldown/main.cpp 5
42 45 */
@@ -26,7 +26,7
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 //! [2]
29 //! [1]
30 30 class DrilldownChart : public QChart
31 31 {
32 32 Q_OBJECT
@@ -41,6 +41,6 public Q_SLOTS:
41 41 private:
42 42 DrilldownBarSeries* m_currentSeries;
43 43 };
44 //! [2]
44 //! [1]
45 45
46 46 #endif // DRILLDOWNCHART_H
@@ -30,18 +30,16 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 int main(int argc, char *argv[])
32 32 {
33 //! [1]
34 33 QApplication a(argc, argv);
35 34 QMainWindow window;
36 //! [1]
37 35
38 //! [2]
36 //! [1]
39 37 DrilldownChart* drilldownChart = new DrilldownChart();
40 38 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
41 39 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
42 //! [2]
40 //! [1]
43 41
44 //! [3]
42 //! [2]
45 43 // Define categories
46 44 QStringList months;
47 45 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
@@ -49,9 +47,9 int main(int argc, char *argv[])
49 47 weeks << "week 1" << "week 2" << "week 3" << "week 4";
50 48 QStringList plants;
51 49 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
52 //! [3]
50 //! [2]
53 51
54 //! [4]
52 //! [3]
55 53 // Create drilldown structure
56 54 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
57 55 seasonSeries->setName("Crop by month - Season");
@@ -75,9 +73,9 int main(int argc, char *argv[])
75 73
76 74 // Enable drilldown from season series using right click.
77 75 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int)));
78 //! [4]
76 //! [3]
79 77
80 //! [5]
78 //! [4]
81 79 // Fill monthly and weekly series with data
82 80 foreach (QString plant, plants) {
83 81 QBarSet* monthlyCrop = new QBarSet(plant);
@@ -92,20 +90,20 int main(int argc, char *argv[])
92 90 }
93 91 seasonSeries->append(monthlyCrop);
94 92 }
95 //! [5]
93 //! [4]
96 94
97 //! [6]
95 //! [5]
98 96 // Show season series in initial view
99 97 drilldownChart->changeSeries(seasonSeries);
100 98 drilldownChart->setTitle(seasonSeries->name());
101 //! [6]
99 //! [5]
102 100
103 //! [7]
101 //! [6]
104 102 drilldownChart->axisX()->setGridLineVisible(false);
105 103 drilldownChart->axisY()->setNiceNumbersEnabled(true);
106 104 drilldownChart->legend()->setVisible(true);
107 105 drilldownChart->legend()->setAlignment(Qt::AlignBottom);
108 //! [7]
106 //! [6]
109 107
110 108 QChartView *chartView = new QChartView(drilldownChart);
111 109 window.setCentralWidget(chartView);
General Comments 0
You need to be logged in to leave comments. Login now