Wt examples  3.3.0
Public Member Functions | List of all members
ScatterPlotExample Class Reference

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

#include <ChartsExample.h>

Inheritance diagram for ScatterPlotExample:
Inheritance graph
[legend]

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from Wt::WWidget
virtual void enableAjax ()=0
 
virtual void propagateSetEnabled (bool enabled)=0
 
virtual void render (WFlags< RenderFlag > flags)
 

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

252  :
253  WContainerWidget(parent)
254 {
255  new WText(WString::tr("scatter plot 2"), this);
256 
257  WStandardItemModel *model = new WStandardItemModel(40, 2, this);
258  model->setHeaderData(0, WString("X"));
259  model->setHeaderData(1, WString("Y = sin(X)"));
260 
261  for (unsigned i = 0; i < 40; ++i) {
262  double x = (static_cast<double>(i) - 20) / 4;
263 
264  model->setData(i, 0, x);
265  model->setData(i, 1, sin(x));
266  }
267 
268  /*
269  * Create the scatter plot.
270  */
271  WCartesianChart *chart = new WCartesianChart(this);
272  chart->setModel(model); // set the model
273  chart->setXSeriesColumn(0); // set the column that holds the X data
274  chart->setLegendEnabled(true); // enable the legend
275 
276  chart->setType(ScatterPlot); // set type to ScatterPlot
277 
278  // Typically, for mathematical functions, you want the axes to cross
279  // at the 0 mark:
280  chart->axis(XAxis).setLocation(ZeroValue);
281  chart->axis(YAxis).setLocation(ZeroValue);
282 
283  // Provide space for the X and Y axis and title.
284  chart->setPlotAreaPadding(80, Left);
285  chart->setPlotAreaPadding(40, Top | Bottom);
286 
287  // Add the curves
288  WDataSeries s(1, CurveSeries);
289  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
290  chart->addSeries(s);
291 
292  chart->resize(800, 300); // WPaintedWidget must be given explicit size
293 
294  chart->setMargin(10, Top | Bottom); // add margin vertically
295  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
296 
297  ChartConfig *config = new ChartConfig(chart, this);
298  config->setValueFill(ZeroValueFill);
299 }

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

Generated on Thu Oct 24 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.4