#include <ChartsExample.h>
Public Member Functions | |
TimeSeriesExample (Wt::WContainerWidget *parent) | |
Creates the time series scatter plot example. |
Definition at line 29 of file ChartsExample.h.
TimeSeriesExample::TimeSeriesExample | ( | Wt::WContainerWidget * | parent | ) |
Creates the time series scatter plot example.
Definition at line 127 of file ChartsExample.C.
00127 : 00128 WContainerWidget(parent) 00129 { 00130 new WText(WString::tr("scatter plot"), this); 00131 00132 WAbstractItemModel *model = readCsvFile("timeseries.csv", this); 00133 00134 if (!model) 00135 return; 00136 00137 /* 00138 * Parse the first column as dates 00139 */ 00140 for (int i = 0; i < model->rowCount(); ++i) { 00141 WString s = asString(model->data(i, 0)); 00142 WDate d = WDate::fromString(s, "dd/MM/yy"); 00143 model->setData(i, 0, boost::any(d)); 00144 } 00145 00146 /* 00147 * Create the scatter plot. 00148 */ 00149 WCartesianChart *chart = new WCartesianChart(this); 00150 chart->setModel(model); // set the model 00151 chart->setXSeriesColumn(0); // set the column that holds the X data 00152 chart->setLegendEnabled(true); // enable the legend 00153 00154 chart->setType(ScatterPlot); // set type to ScatterPlot 00155 chart->axis(XAxis).setScale(DateScale); // set scale of X axis to DateScale 00156 00157 // Provide space for the X and Y axis and title. 00158 chart->setPlotAreaPadding(100, Left); 00159 chart->setPlotAreaPadding(50, Top | Bottom); 00160 00161 /* 00162 * Add first two columns as line series 00163 */ 00164 for (int i = 1; i < 3; ++i) { 00165 WDataSeries s(i, LineSeries); 00166 chart->addSeries(s); 00167 } 00168 00169 chart->resize(800, 400); // WPaintedWidget must be given explicit size 00170 00171 chart->setMargin(10, Top | Bottom); // add margin vertically 00172 chart->setMargin(WLength(), Left | Right); // center horizontally 00173 00174 new ChartConfig(chart, this); 00175 }