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.

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

The documentation for this class was generated from the following files:
Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1