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

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

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