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