Wt examples  3.3.1
Public Member Functions | List of all members
PieExample Class Reference

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

#include <ChartsExample.h>

Inheritance diagram for PieExample:
Inheritance graph
[legend]

Public Member Functions

 PieExample (Wt::WContainerWidget *parent)
 Creates the pie 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 Pie chart.

Definition at line 59 of file ChartsExample.h.

Constructor & Destructor Documentation

PieExample::PieExample ( Wt::WContainerWidget parent)

Creates the pie chart example.

Definition at line 301 of file ChartsExample.C.

301  :
302  WContainerWidget(parent)
303 {
304  new WText(WString::tr("pie chart"), this);
305 
306  WStandardItemModel *model = new WStandardItemModel(this);
307 
308  //headers
309  model->insertColumns(model->columnCount(), 2);
310  model->setHeaderData(0, WString("Item"));
311  model->setHeaderData(1, WString("Sales"));
312 
313  //data
314  model->insertRows(model->rowCount(), 6);
315  int row = 0;
316  model->setData(row, 0, WString("Blueberry"));
317  model->setData(row, 1, 120);
318  // model->setData(row, 1, WString("Blueberry"), ToolTipRole);
319  row++;
320  model->setData(row, 0, WString("Cherry"));
321  model->setData(row, 1, 30);
322  row++;
323  model->setData(row, 0, WString("Apple"));
324  model->setData(row, 1, 260);
325  row++;
326  model->setData(row, 0, WString("Boston Cream"));
327  model->setData(row, 1, 160);
328  row++;
329  model->setData(row, 0, WString("Other"));
330  model->setData(row, 1, 40);
331  row++;
332  model->setData(row, 0, WString("Vanilla Cream"));
333  model->setData(row, 1, 120);
334  row++;
335 
336  //set all items to be editable and selectable
337  for (int row = 0; row < model->rowCount(); ++row)
338  for (int col = 0; col < model->columnCount(); ++col)
339  model->item(row, col)->setFlags(ItemIsSelectable | ItemIsEditable);
340 
341  WContainerWidget *w = new WContainerWidget(this);
342  WTableView* table = new WTableView(w);
343 
344  table->setMargin(10, Top | Bottom);
345  table->setMargin(WLength::Auto, Left | Right);
346  table->setSortingEnabled(true);
347  table->setModel(model);
348  table->setColumnWidth(1, 100);
349  table->setRowHeight(22);
350 
351  if (WApplication::instance()->environment().ajax()) {
352  table->resize(150 + 100 + 14, 20 + 6 * 22);
353  table->setEditTriggers(WAbstractItemView::SingleClicked);
354  } else {
355  table->resize(150 + 100 + 14, WLength::Auto);
356  table->setEditTriggers(WAbstractItemView::NoEditTrigger);
357  }
358 
359  /*
360  * Create the pie chart.
361  */
362  WPieChart *chart = new WPieChart(this);
363  chart->setModel(model); // set the model
364  chart->setLabelsColumn(0); // set the column that holds the labels
365  chart->setDataColumn(1); // set the column that holds the data
366 
367  // configure location and type of labels
369 
370  // enable a 3D and shadow effect
371  chart->setPerspectiveEnabled(true, 0.2);
372  chart->setShadowEnabled(true);
373 
374  // explode the first item
375  chart->setExplode(0, 0.3);
376 
377  chart->resize(800, 300); // WPaintedWidget must be given an explicit size
378 
379  chart->setMargin(10, Top | Bottom); // add margin vertically
380  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
381 }

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

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