##// END OF EJS Templates
Doc update
Marek Rosa -
r382:e98d5f6bcbb9
parent child
Show More
@@ -16,6 +16,7
16 16 <li><a href="example-barchart.html">Bar Chart example</a></li>
17 17 <li><a href="example-linechart.html">Line Chart example</a></li>
18 18 <li><a href="example-piechart.html">Pie Chart example</a></li>
19 <li><a href="example-gdpbarchart.html">GDP Chart example</a></li>
19 20 </ul>
20 21 </td>
21 22 </tr>
@@ -35,6 +35,7 Widget::Widget(QWidget *parent)
35 35 countrieslist = new QListWidget;
36 36 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
37 37
38 //list of years widget
38 39 yearslist = new QListWidget;
39 40 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
40 41 for (int i = 1990; i < 2011; i++)
@@ -101,7 +102,7 Widget::~Widget()
101 102 */
102 103 void Widget::refreshChart()
103 104 {
104 chartArea->removeAllSeries();
105 chartArea->removeAllSeries();
105 106
106 107 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
107 108 QStringList selectedCountriesStrings;
@@ -111,7 +112,7 void Widget::refreshChart()
111 112 selectedCountriesStrings.sort();
112 113
113 114 QSqlQuery query;
114 // selected years items list is not sorted. copy the values to QList<Integer> and sort them.
115 // selected years items list is not sorted. copy the values to QList<int> and sort them.
115 116 QList<int> selectedYearsInts;
116 117 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
117 118 for (int i = 0; i < selectedYearsItems.size(); i++)
@@ -119,12 +120,12 void Widget::refreshChart()
119 120 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
120 121
121 122 if (barChartRadioButton->isChecked())
122 {
123 {
123 124 // use the sorted selected coutries list to initialize BarCategory
124 125 QBarCategory* category = new QBarCategory;
125 126 for (int i = 0; i < selectedCountriesStrings.size(); i++)
126 127 *category << selectedCountriesStrings[i];
127 series0 = new QBarChartSeries(category);
128 QBarChartSeries* series0 = new QBarChartSeries(category);
128 129
129 130 // prepare the selected counries SQL query
130 131 QString countriesQuery = "country IN (";
@@ -162,14 +163,13 void Widget::refreshChart()
162 163 {
163 164 // data missing, put 0
164 165 *barSet << 0.0f;
165 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]);
166 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
166 167 }
167 168 }
168 169 series0->addBarSet(barSet);
169 170 }
170 171 // add the serie to the chart
171 172 chartArea->addSeries(series0);
172
173 173 }
174 174 else if (scatterChartRadioButton->isChecked())
175 175 {
@@ -183,7 +183,7 void Widget::refreshChart()
183 183 yearsQuery.append(")");
184 184 }
185 185
186 // perform a query for each selected year
186 // perform a query for each selected country
187 187 for (int i = 0; i < selectedCountriesStrings.size(); i++)
188 188 {
189 189 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
@@ -203,7 +203,7 void Widget::refreshChart()
203 203 {
204 204 // data missing, put 0
205 205 *series << QPointF(selectedYearsInts[k] , 0.0f);
206 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
206 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
207 207 }
208 208 }
209 209 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
@@ -28,7 +28,7 private:
28 28 QListWidget* countrieslist;
29 29 QListWidget* yearslist;
30 30 QSqlDatabase db;
31 QBarChartSeries* series0;
31 // QBarChartSeries* series0;
32 32 QRadioButton* barChartRadioButton;
33 33 QRadioButton* scatterChartRadioButton;
34 34 };
General Comments 0
You need to be logged in to leave comments. Login now