Public Member Functions

TimeSeriesExample Class Reference
[Charts example]

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

#include <ChartsExample.h>

Inherits Wt::WContainerWidget.

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.

                                                              :
  WContainerWidget(parent)
{
  new WText(WString::tr("scatter plot"), this);

  WAbstractItemModel *model = readCsvFile("timeseries.csv", this);

  if (!model)
    return;

  /*
   * Parse the first column as dates
   */
  for (int i = 0; i < model->rowCount(); ++i) {
    WString s = asString(model->data(i, 0));
    WDate d = WDate::fromString(s, "dd/MM/yy");
    model->setData(i, 0, boost::any(d));
  }

  /*
   * Create the scatter plot.
   */
  WCartesianChart *chart = new WCartesianChart(this);
  chart->setModel(model);        // set the model
  chart->setXSeriesColumn(0);    // set the column that holds the X data
  chart->setLegendEnabled(true); // enable the legend

  chart->setType(ScatterPlot);            // set type to ScatterPlot
  chart->axis(XAxis).setScale(DateScale); // set scale of X axis to DateScale

  // Provide space for the X and Y axis and title. 
  chart->setPlotAreaPadding(100, Left);
  chart->setPlotAreaPadding(50, Top | Bottom);

  /*
   * Add first two columns as line series
   */
  for (int i = 1; i < 3; ++i) {
    WDataSeries s(i, LineSeries);
    s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
    chart->addSeries(s);
  }

  chart->resize(800, 400); // WPaintedWidget must be given explicit size

  chart->setMargin(10, Top | Bottom);            // add margin vertically
  chart->setMargin(WLength::Auto, Left | Right); // center horizontally

  new ChartConfig(chart, this);
}


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

Generated on Mon Nov 29 2010 08:03:14 for Wt by doxygen 1.7.1