|
Wt examples
3.3.5
|
A Widget that demonstrates a category chart. More...
#include <ChartsExample.h>
Public Member Functions | |
| CategoryExample (Wt::WContainerWidget *parent) | |
| Creates the category chart example. | |
A Widget that demonstrates a category chart.
Definition at line 39 of file ChartsExample.h.
| CategoryExample::CategoryExample | ( | Wt::WContainerWidget * | parent | ) |
Creates the category chart example.
Definition at line 111 of file ChartsExample.C.
:
WContainerWidget(parent)
{
new WText(WString::tr("category chart"), this);
WAbstractItemModel *model
= readCsvFile(WApplication::appRoot() + "category.csv", this);
if (!model)
return;
// Show a view that allows editing of the model.
WContainerWidget *w = new WContainerWidget(this);
WTableView *table = new WTableView(w);
table->setMargin(10, Top | Bottom);
table->setMargin(WLength::Auto, Left | Right);
table->setModel(model);
table->setSortingEnabled(true);
table->setColumnResizeEnabled(true);
// table->setSelectionMode(ExtendedSelection);
table->setAlternatingRowColors(true);
table->setColumnAlignment(0, AlignCenter);
table->setHeaderAlignment(0, AlignCenter);
table->setRowHeight(22);
// Editing does not really work without Ajax, it would require an
// additional button somewhere to confirm the edited value.
if (WApplication::instance()->environment().ajax()) {
table->resize(600, 20 + 5*22);
table->setEditTriggers(WAbstractItemView::SingleClicked);
} else {
table->resize(600, WLength::Auto);
table->setEditTriggers(WAbstractItemView::NoEditTrigger);
}
// We use a single delegate for all items which rounds values to
// the closest integer value.
WItemDelegate *delegate = new WItemDelegate(this);
delegate->setTextFormat("%.f");
table->setItemDelegate(delegate);
table->setColumnWidth(0, 80);
for (int i = 1; i < model->columnCount(); ++i)
table->setColumnWidth(i, 120);
/*
* Create the category chart.
*/
WCartesianChart *chart = new WCartesianChart(this);
chart->setModel(model); // set the model
chart->setXSeriesColumn(0); // set the column that holds the categories
chart->setLegendEnabled(true); // enable the legend
chart->setZoomEnabled(true);
chart->setPanEnabled(true);
// Automatically layout chart (space for axes, legend, ...)
chart->setAutoLayoutEnabled(true);
chart->setBackground(WColor(200,200,200));
/*
* Add all (but first) column as bar series
*/
for (int i = 1; i < model->columnCount(); ++i) {
WDataSeries s(i, BarSeries);
s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
chart->addSeries(s);
}
chart->resize(800, 400);
chart->setMargin(10, Top | Bottom);
chart->setMargin(WLength::Auto, Left | Right);
/*
* Provide a widget to manipulate chart properties
*/
new ChartConfig(chart, this);
}
1.7.6.1