ScatterPlotExample Class Reference
[Charts example]

A Widget that demonstrates a scatter plot. More...

#include <ChartsExample.h>

Inheritance diagram for ScatterPlotExample:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 ScatterPlotExample (Wt::WContainerWidget *parent)
 Creates the scatter plot example.


Detailed Description

A Widget that demonstrates a scatter plot.

Definition at line 49 of file ChartsExample.h.


Constructor & Destructor Documentation

ScatterPlotExample::ScatterPlotExample ( Wt::WContainerWidget parent  ) 

Creates the scatter plot example.

Definition at line 177 of file ChartsExample.C.

00177                                                               :
00178   WContainerWidget(parent)
00179 {
00180   new WText(WString::tr("scatter plot 2"), this);
00181 
00182   WStandardItemModel *model = new WStandardItemModel(40, 2, this);
00183   model->setHeaderData(0, boost::any(WString("X")));
00184   model->setHeaderData(1, boost::any(WString("Y = sin(X)")));
00185 
00186   for (unsigned i = 0; i < 40; ++i) {
00187     double x = (static_cast<double>(i) - 20) / 4;
00188 
00189     model->setData(i, 0, boost::any(x));
00190     model->setData(i, 1, boost::any(sin(x)));
00191   }
00192  
00193   /*
00194    * Create the scatter plot.
00195    */
00196   WCartesianChart *chart = new WCartesianChart(this);
00197   chart->setModel(model);        // set the model
00198   chart->setXSeriesColumn(0);    // set the column that holds the X data
00199   chart->setLegendEnabled(true); // enable the legend
00200 
00201   chart->setType(ScatterPlot);   // set type to ScatterPlot
00202 
00203   // Typically, for mathematical functions, you want the axes to cross
00204   // at the 0 mark:
00205   chart->axis(XAxis).setLocation(ZeroValue);
00206   chart->axis(YAxis).setLocation(ZeroValue);
00207 
00208   // Provide space for the X and Y axis and title. 
00209   chart->setPlotAreaPadding(100, Left);
00210   chart->setPlotAreaPadding(50, Top | Bottom);
00211 
00212   // Add the two curves
00213   chart->addSeries(WDataSeries(1, CurveSeries));
00214 
00215   chart->resize(800, 300); // WPaintedWidget must be given explicit size
00216 
00217   chart->setMargin(10, Top | Bottom);            // add margin vertically
00218   chart->setMargin(WLength::Auto, Left | Right); // center horizontally
00219 
00220   ChartConfig *config = new ChartConfig(chart, this);
00221   config->setValueFill(ZeroValueFill);
00222 }


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

Generated on Tue Nov 3 15:34:40 2009 for Wt by doxygen 1.5.6