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 235 of file ChartsExample.C.

00235                                                               :
00236   WContainerWidget(parent)
00237 {
00238   new WText(WString::tr("scatter plot 2"), this);
00239 
00240   WStandardItemModel *model = new WStandardItemModel(40, 2, this);
00241   model->setHeaderData(0, boost::any(WString("X")));
00242   model->setHeaderData(1, boost::any(WString("Y = sin(X)")));
00243 
00244   for (unsigned i = 0; i < 40; ++i) {
00245     double x = (static_cast<double>(i) - 20) / 4;
00246 
00247     model->setData(i, 0, boost::any(x));
00248     model->setData(i, 1, boost::any(sin(x)));
00249   }
00250  
00251   /*
00252    * Create the scatter plot.
00253    */
00254   WCartesianChart *chart = new WCartesianChart(this);
00255   chart->setModel(model);        // set the model
00256   chart->setXSeriesColumn(0);    // set the column that holds the X data
00257   chart->setLegendEnabled(true); // enable the legend
00258 
00259   chart->setType(ScatterPlot);   // set type to ScatterPlot
00260 
00261   // Typically, for mathematical functions, you want the axes to cross
00262   // at the 0 mark:
00263   chart->axis(XAxis).setLocation(ZeroValue);
00264   chart->axis(YAxis).setLocation(ZeroValue);
00265 
00266   // Provide space for the X and Y axis and title. 
00267   chart->setPlotAreaPadding(100, Left);
00268   chart->setPlotAreaPadding(50, Top | Bottom);
00269 
00270   // Add the curves
00271   WDataSeries s(1, CurveSeries);
00272   s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
00273   chart->addSeries(s);
00274 
00275   chart->resize(800, 300); // WPaintedWidget must be given explicit size
00276 
00277   chart->setMargin(10, Top | Bottom);            // add margin vertically
00278   chart->setMargin(WLength::Auto, Left | Right); // center horizontally
00279 
00280   ChartConfig *config = new ChartConfig(chart, this);
00281   config->setValueFill(ZeroValueFill);
00282 }


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

Generated on Thu May 20 18:14:57 2010 for Wt by doxygen 1.5.6