Wt examples  4.0.5
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 ()
 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 ( )

Creates the scatter plot example.

Definition at line 294 of file ChartsExample.C.

294  :
295  WContainerWidget()
296 {
297  this->addWidget(cpp14::make_unique<WText>(WString::tr("scatter plot 2")));
298 
299  std::shared_ptr<WStandardItemModel> model
300  = std::make_shared<WStandardItemModel>(40, 2);
301  std::unique_ptr<NumericItem> prototype
302  = cpp14::make_unique<NumericItem>();
303  model->setItemPrototype(std::move(prototype));
304  model->setHeaderData(0, WString("X"));
305  model->setHeaderData(1, WString("Y = sin(X)"));
306 
307  for (unsigned i = 0; i < 40; ++i) {
308  double x = (static_cast<double>(i) - 20) / 4;
309 
310  model->setData(i, 0, x);
311  model->setData(i, 1, sin(x));
312  }
313 
314  /*
315  * Create the scatter plot.
316  */
317  WCartesianChart *chart = this->addWidget(cpp14::make_unique<WCartesianChart>());
318  chart->setModel(model); // set the model
319  chart->setXSeriesColumn(0); // set the column that holds the X data
320  chart->setLegendEnabled(true); // enable the legend
321  chart->setZoomEnabled(true);
322  chart->setPanEnabled(true);
323  chart->setCrosshairEnabled(true);
324 
325  chart->setBackground(WColor(200,200,200));
326 
327  chart->setType(ChartType::Scatter); // set type to ScatterPlot
328 
329  // Typically, for mathematical functions, you want the axes to cross
330  // at the 0 mark:
331  chart->axis(Axis::X).setLocation(AxisValue::Zero);
332  chart->axis(Axis::Y).setLocation(AxisValue::Zero);
333 
334  // Automatically layout chart (space for axes, legend, ...)
335  chart->setAutoLayoutEnabled();
336 
337  // Add the curves
338  std::unique_ptr<WDataSeries> s
339  = cpp14::make_unique<WDataSeries>(1, SeriesType::Curve);
340  s->setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
341  chart->addSeries(std::move(s));
342 
343  chart->resize(800, 300); // WPaintedWidget must be given explicit size
344 
345  chart->setMargin(10, Side::Top | Side::Bottom); // add margin vertically
346  chart->setMargin(WLength::Auto, Side::Left | Side::Right); // center horizontally
347 
348  ChartConfig *config = this->addWidget(cpp14::make_unique<ChartConfig>(chart));
349  config->setValueFill(FillRangeType::ZeroValue);
350 }
void setValueFill(Wt::Chart::FillRangeType fill)
Definition: ChartConfig.C:378
A class that allows configuration of a cartesian chart.
Definition: ChartConfig.h:40

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

Generated on Mon May 20 2019 for the C++ Web Toolkit (Wt) by doxygen 1.8.14