Wt examples  3.3.0
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...
 

Additional Inherited Members

- Protected Member Functions inherited from Wt::WWidget
virtual void enableAjax ()=0
 
virtual void propagateSetEnabled (bool enabled)=0
 
virtual void render (WFlags< RenderFlag > flags)
 

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 83 of file ChartsExample.C.

83  :
84  WContainerWidget(parent)
85 {
86  new WText(WString::tr("category chart"), this);
87 
88  WAbstractItemModel *model
89  = readCsvFile(WApplication::appRoot() + "category.csv", this);
90 
91  if (!model)
92  return;
93 
94  // Show a view that allows editing of the model.
95  WContainerWidget *w = new WContainerWidget(this);
96  WTableView *table = new WTableView(w);
97 
98  table->setMargin(10, Top | Bottom);
99  table->setMargin(WLength::Auto, Left | Right);
100 
101  table->setModel(model);
102  table->setSortingEnabled(true);
103  table->setColumnResizeEnabled(true);
104  // table->setSelectionMode(ExtendedSelection);
105  table->setAlternatingRowColors(true);
106  table->setColumnAlignment(0, AlignCenter);
107  table->setHeaderAlignment(0, AlignCenter);
108  table->setRowHeight(22);
109 
110  // Editing does not really work without Ajax, it would require an
111  // additional button somewhere to confirm the edited value.
112  if (WApplication::instance()->environment().ajax()) {
113  table->resize(600, 20 + 5*22);
114  table->setEditTriggers(WAbstractItemView::SingleClicked);
115  } else {
116  table->resize(600, WLength::Auto);
117  table->setEditTriggers(WAbstractItemView::NoEditTrigger);
118  }
119 
120  // We use a single delegate for all items which rounds values to
121  // the closest integer value.
122  WItemDelegate *delegate = new WItemDelegate(this);
123  delegate->setTextFormat("%.f");
124  table->setItemDelegate(delegate);
125 
126  table->setColumnWidth(0, 80);
127  for (int i = 1; i < model->columnCount(); ++i)
128  table->setColumnWidth(i, 120);
129 
130  /*
131  * Create the category chart.
132  */
133  WCartesianChart *chart = new WCartesianChart(this);
134  // chart->setPreferredMethod(WPaintedWidget::PngImage);
135  chart->setModel(model); // set the model
136  chart->setXSeriesColumn(0); // set the column that holds the categories
137  chart->setLegendEnabled(true); // enable the legend
138 
139  // Provide space for the X and Y axis and title.
140  chart->setPlotAreaPadding(80, Left);
141  chart->setPlotAreaPadding(40, Top | Bottom);
142 
143  /*
144  * Add all (but first) column as bar series
145  */
146  for (int i = 1; i < model->columnCount(); ++i) {
147  WDataSeries s(i, BarSeries);
148  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
149  chart->addSeries(s);
150  }
151 
152  chart->resize(800, 400);
153 
154  chart->setMargin(10, Top | Bottom);
155  chart->setMargin(WLength::Auto, Left | Right);
156 
157  /*
158  * Provide a widget to manipulate chart properties
159  */
160  new ChartConfig(chart, this);
161 }

The documentation for this class was generated from the following files:

Generated on Thu Oct 24 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.4