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

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


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