A Widget that demonstrates a scatter plot. More...
#include <ChartsExample.h>
Public Member Functions | |
ScatterPlotExample (Wt::WContainerWidget *parent) | |
Creates the scatter plot example. |
A Widget that demonstrates a scatter plot.
Definition at line 49 of file ChartsExample.h.
ScatterPlotExample::ScatterPlotExample | ( | Wt::WContainerWidget * | parent ) |
Creates the scatter plot example.
Definition at line 252 of file ChartsExample.C.
: WContainerWidget(parent) { new WText(WString::tr("scatter plot 2"), this); WStandardItemModel *model = new WStandardItemModel(40, 2, this); model->setHeaderData(0, WString("X")); model->setHeaderData(1, WString("Y = sin(X)")); for (unsigned i = 0; i < 40; ++i) { double x = (static_cast<double>(i) - 20) / 4; model->setData(i, 0, x); model->setData(i, 1, sin(x)); } /* * Create the scatter plot. */ WCartesianChart *chart = new WCartesianChart(this); chart->setModel(model); // set the model chart->setXSeriesColumn(0); // set the column that holds the X data chart->setLegendEnabled(true); // enable the legend chart->setType(ScatterPlot); // set type to ScatterPlot // Typically, for mathematical functions, you want the axes to cross // at the 0 mark: chart->axis(XAxis).setLocation(ZeroValue); chart->axis(YAxis).setLocation(ZeroValue); // Provide space for the X and Y axis and title. chart->setPlotAreaPadding(80, Left); chart->setPlotAreaPadding(40, Top | Bottom); // Add the curves WDataSeries s(1, CurveSeries); s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3)); chart->addSeries(s); chart->resize(800, 300); // WPaintedWidget must be given explicit size chart->setMargin(10, Top | Bottom); // add margin vertically chart->setMargin(WLength::Auto, Left | Right); // center horizontally ChartConfig *config = new ChartConfig(chart, this); config->setValueFill(ZeroValueFill); }