A Widget that demonstrates a scatter plot. More...
#include <ChartsExample.h>
Inherits Wt::WContainerWidget.
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 179 of file ChartsExample.C.
00180 : 00181 WContainerWidget(parent) 00182 { 00183 new WText(WString::tr("scatter plot 2"), this); 00184 00185 WStandardItemModel *model = new WStandardItemModel(40, 2, this); 00186 model->setHeaderData(0, boost::any(WString("X"))); 00187 model->setHeaderData(1, boost::any(WString("Y = sin(X)"))); 00188 00189 for (unsigned i = 0; i < 40; ++i) { 00190 double x = (static_cast<double>(i) - 20) / 4; 00191 00192 model->setData(i, 0, boost::any(x)); 00193 model->setData(i, 1, boost::any(sin(x))); 00194 } 00195 00196 /* 00197 * Create the scatter plot. 00198 */ 00199 WCartesianChart *chart = new WCartesianChart(this); 00200 chart->setModel(model); // set the model 00201 chart->setXSeriesColumn(0); // set the column that holds the X data 00202 chart->setLegendEnabled(true); // enable the legend 00203 00204 chart->setType(ScatterPlot); // set type to ScatterPlot 00205 00206 // Typically, for mathematical functions, you want the axes to cross 00207 // at the 0 mark: 00208 chart->axis(XAxis).setLocation(ZeroValue); 00209 chart->axis(YAxis).setLocation(ZeroValue); 00210 00211 // Provide space for the X and Y axis and title. 00212 chart->setPlotAreaPadding(100, Left); 00213 chart->setPlotAreaPadding(50, Top | Bottom); 00214 00215 // Add the curves 00216 WDataSeries s(1, CurveSeries); 00217 s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3)); 00218 chart->addSeries(s); 00219 00220 chart->resize(800, 300); // WPaintedWidget must be given explicit size 00221 00222 chart->setMargin(10, Top | Bottom); // add margin vertically 00223 chart->setMargin(WLength::Auto, Left | Right); // center horizontally 00224 00225 ChartConfig *config = new ChartConfig(chart, this); 00226 config->setValueFill(ZeroValueFill); }