Wt examples  3.3.3
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 280 of file ChartsExample.C.

280  :
281  WContainerWidget(parent)
282 {
283  new WText(WString::tr("scatter plot 2"), this);
284 
285  WStandardItemModel *model = new WStandardItemModel(40, 2, this);
286  model->setItemPrototype(new NumericItem());
287  model->setHeaderData(0, WString("X"));
288  model->setHeaderData(1, WString("Y = sin(X)"));
289 
290  for (unsigned i = 0; i < 40; ++i) {
291  double x = (static_cast<double>(i) - 20) / 4;
292 
293  model->setData(i, 0, x);
294  model->setData(i, 1, sin(x));
295  }
296 
297  /*
298  * Create the scatter plot.
299  */
300  WCartesianChart *chart = new WCartesianChart(this);
301  chart->setModel(model); // set the model
302  chart->setXSeriesColumn(0); // set the column that holds the X data
303  chart->setLegendEnabled(true); // enable the legend
304 
305  chart->setType(ScatterPlot); // set type to ScatterPlot
306 
307  // Typically, for mathematical functions, you want the axes to cross
308  // at the 0 mark:
309  chart->axis(XAxis).setLocation(ZeroValue);
310  chart->axis(YAxis).setLocation(ZeroValue);
311 
312  // Provide space for the X and Y axis and title.
313  chart->setPlotAreaPadding(80, Left);
314  chart->setPlotAreaPadding(40, Top | Bottom);
315 
316  // Add the curves
317  WDataSeries s(1, CurveSeries);
318  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
319  chart->addSeries(s);
320 
321  chart->resize(800, 300); // WPaintedWidget must be given explicit size
322 
323  chart->setMargin(10, Top | Bottom); // add margin vertically
324  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
325 
326  ChartConfig *config = new ChartConfig(chart, this);
327  config->setValueFill(ZeroValueFill);
328 }

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

Generated on Tue May 27 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.4