Wt examples  3.3.6
Public Member Functions | List of all members
CategoryExample Class Reference

A Widget that demonstrates a category chart. More...

#include <ChartsExample.h>

Inheritance diagram for CategoryExample:
Inheritance graph
[legend]

Public Member Functions

 CategoryExample (Wt::WContainerWidget *parent)
 Creates the category chart example. More...
 

Detailed Description

A Widget that demonstrates a category chart.

Definition at line 39 of file ChartsExample.h.

Constructor & Destructor Documentation

§ CategoryExample()

CategoryExample::CategoryExample ( Wt::WContainerWidget *  parent)

Creates the category chart example.

Definition at line 111 of file ChartsExample.C.

111  :
112  WContainerWidget(parent)
113 {
114  new WText(WString::tr("category chart"), this);
115 
116  WAbstractItemModel *model
117  = readCsvFile(WApplication::appRoot() + "category.csv", this);
118 
119  if (!model)
120  return;
121 
122  // Show a view that allows editing of the model.
123  WContainerWidget *w = new WContainerWidget(this);
124  WTableView *table = new WTableView(w);
125 
126  table->setMargin(10, Top | Bottom);
127  table->setMargin(WLength::Auto, Left | Right);
128 
129  table->setModel(model);
130  table->setSortingEnabled(true);
131  table->setColumnResizeEnabled(true);
132  // table->setSelectionMode(ExtendedSelection);
133  table->setAlternatingRowColors(true);
134  table->setColumnAlignment(0, AlignCenter);
135  table->setHeaderAlignment(0, AlignCenter);
136  table->setRowHeight(22);
137 
138  // Editing does not really work without Ajax, it would require an
139  // additional button somewhere to confirm the edited value.
140  if (WApplication::instance()->environment().ajax()) {
141  table->resize(600, 20 + 5*22);
142  table->setEditTriggers(WAbstractItemView::SingleClicked);
143  } else {
144  table->resize(600, WLength::Auto);
145  table->setEditTriggers(WAbstractItemView::NoEditTrigger);
146  }
147 
148  // We use a single delegate for all items which rounds values to
149  // the closest integer value.
150  WItemDelegate *delegate = new WItemDelegate(this);
151  delegate->setTextFormat("%.f");
152  table->setItemDelegate(delegate);
153 
154  table->setColumnWidth(0, 80);
155  for (int i = 1; i < model->columnCount(); ++i)
156  table->setColumnWidth(i, 120);
157 
158  /*
159  * Create the category chart.
160  */
161  WCartesianChart *chart = new WCartesianChart(this);
162  chart->setModel(model); // set the model
163  chart->setXSeriesColumn(0); // set the column that holds the categories
164  chart->setLegendEnabled(true); // enable the legend
165  chart->setZoomEnabled(true);
166  chart->setPanEnabled(true);
167 
168  // Automatically layout chart (space for axes, legend, ...)
169  chart->setAutoLayoutEnabled(true);
170 
171  chart->setBackground(WColor(200,200,200));
172 
173  /*
174  * Add all (but first) column as bar series
175  */
176  for (int i = 1; i < model->columnCount(); ++i) {
177  WDataSeries *s = new WDataSeries(i, BarSeries);
178  s->setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
179  chart->addSeries(s);
180  }
181 
182  chart->resize(800, 400);
183 
184  chart->setMargin(10, Top | Bottom);
185  chart->setMargin(WLength::Auto, Left | Right);
186 
187  /*
188  * Provide a widget to manipulate chart properties
189  */
190  new ChartConfig(chart, this);
191 }
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.12