TimeSeriesExample Class Reference
[Charts example]

A widget that demonstrates a times series chart. More...

#include <ChartsExample.h>

Inheritance diagram for TimeSeriesExample:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 TimeSeriesExample (Wt::WContainerWidget *parent)
 Creates the time series scatter plot example.


Detailed Description

A widget that demonstrates a times series chart.

Definition at line 29 of file ChartsExample.h.


Constructor & Destructor Documentation

TimeSeriesExample::TimeSeriesExample ( Wt::WContainerWidget parent  ) 

Creates the time series scatter plot example.

Definition at line 128 of file ChartsExample.C.

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


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 17:12:12 2010 for Wt by doxygen 1.5.6