Wt examples  3.3.4
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 ( 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->setPreferredMethod(WPaintedWidget::PngImage);
163  chart->setModel(model); // set the model
164  chart->setXSeriesColumn(0); // set the column that holds the categories
165  chart->setLegendEnabled(true); // enable the legend
166 
167  // Automatically layout chart (space for axes, legend, ...)
168  chart->setAutoLayoutEnabled(true);
169 
170  /*
171  * Add all (but first) column as bar series
172  */
173  for (int i = 1; i < model->columnCount(); ++i) {
174  WDataSeries s(i, BarSeries);
175  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
176  chart->addSeries(s);
177  }
178 
179  chart->resize(800, 400);
180 
181  chart->setMargin(10, Top | Bottom);
182  chart->setMargin(WLength::Auto, Left | Right);
183 
184  /*
185  * Provide a widget to manipulate chart properties
186  */
187  new ChartConfig(chart, this);
188 }
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 Jul 16 2015 for the C++ Web Toolkit (Wt) by doxygen 1.8.9.1