Wt examples  3.3.6
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...
 

Detailed Description

A Widget that demonstrates a scatter plot.

Definition at line 49 of file ChartsExample.h.

Constructor & Destructor Documentation

◆ ScatterPlotExample()

ScatterPlotExample::ScatterPlotExample ( Wt::WContainerWidget *  parent)

Creates the scatter plot example.

Definition at line 284 of file ChartsExample.C.

284  :
285  WContainerWidget(parent)
286 {
287  new WText(WString::tr("scatter plot 2"), this);
288 
289  WStandardItemModel *model = new WStandardItemModel(40, 2, this);
290  model->setItemPrototype(new NumericItem());
291  model->setHeaderData(0, WString("X"));
292  model->setHeaderData(1, WString("Y = sin(X)"));
293 
294  for (unsigned i = 0; i < 40; ++i) {
295  double x = (static_cast<double>(i) - 20) / 4;
296 
297  model->setData(i, 0, x);
298  model->setData(i, 1, sin(x));
299  }
300 
301  /*
302  * Create the scatter plot.
303  */
304  WCartesianChart *chart = new WCartesianChart(this);
305  chart->setModel(model); // set the model
306  chart->setXSeriesColumn(0); // set the column that holds the X data
307  chart->setLegendEnabled(true); // enable the legend
308  chart->setZoomEnabled(true);
309  chart->setPanEnabled(true);
310  chart->setCrosshairEnabled(true);
311 
312  chart->setBackground(WColor(200,200,200));
313 
314  chart->setType(ScatterPlot); // set type to ScatterPlot
315 
316  // Typically, for mathematical functions, you want the axes to cross
317  // at the 0 mark:
318  chart->axis(XAxis).setLocation(ZeroValue);
319  chart->axis(YAxis).setLocation(ZeroValue);
320 
321  // Automatically layout chart (space for axes, legend, ...)
322  chart->setAutoLayoutEnabled();
323 
324  // Add the curves
325  WDataSeries *s = new WDataSeries(1, CurveSeries);
326  s->setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
327  chart->addSeries(s);
328 
329  chart->resize(800, 300); // WPaintedWidget must be given explicit size
330 
331  chart->setMargin(10, Top | Bottom); // add margin vertically
332  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
333 
334  ChartConfig *config = new ChartConfig(chart, this);
335  config->setValueFill(ZeroValueFill);
336 }
void setValueFill(Wt::Chart::FillRangeType fill)
Definition: ChartConfig.C:435
A class that allows configuration of a cartesian chart.
Definition: ChartConfig.h:37

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

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13