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.

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

The documentation for this class was generated from the following files:
Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1