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

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

330  :
331  WContainerWidget(parent)
332 {
333  new WText(WString::tr("pie chart"), this);
334 
335  WStandardItemModel *model = new WStandardItemModel(this);
336  model->setItemPrototype(new NumericItem());
337 
338  //headers
339  model->insertColumns(model->columnCount(), 2);
340  model->setHeaderData(0, WString("Item"));
341  model->setHeaderData(1, WString("Sales"));
342 
343  //data
344  model->insertRows(model->rowCount(), 6);
345  int row = 0;
346  model->setData(row, 0, WString("Blueberry"));
347  model->setData(row, 1, 120);
348  // model->setData(row, 1, WString("Blueberry"), ToolTipRole);
349  row++;
350  model->setData(row, 0, WString("Cherry"));
351  model->setData(row, 1, 30);
352  row++;
353  model->setData(row, 0, WString("Apple"));
354  model->setData(row, 1, 260);
355  row++;
356  model->setData(row, 0, WString("Boston Cream"));
357  model->setData(row, 1, 160);
358  row++;
359  model->setData(row, 0, WString("Other"));
360  model->setData(row, 1, 40);
361  row++;
362  model->setData(row, 0, WString("Vanilla Cream"));
363  model->setData(row, 1, 120);
364  row++;
365 
366  //set all items to be editable and selectable
367  for (int row = 0; row < model->rowCount(); ++row)
368  for (int col = 0; col < model->columnCount(); ++col)
369  model->item(row, col)->setFlags(ItemIsSelectable | ItemIsEditable);
370 
371  WContainerWidget *w = new WContainerWidget(this);
372  WTableView* table = new WTableView(w);
373 
374  table->setMargin(10, Top | Bottom);
375  table->setMargin(WLength::Auto, Left | Right);
376  table->setSortingEnabled(true);
377  table->setModel(model);
378  table->setColumnWidth(1, 100);
379  table->setRowHeight(22);
380 
381  if (WApplication::instance()->environment().ajax()) {
382  table->resize(150 + 100 + 14, 20 + 6 * 22);
383  table->setEditTriggers(WAbstractItemView::SingleClicked);
384  } else {
385  table->resize(150 + 100 + 14, WLength::Auto);
386  table->setEditTriggers(WAbstractItemView::NoEditTrigger);
387  }
388 
389  /*
390  * Create the pie chart.
391  */
392  WPieChart *chart = new WPieChart(this);
393  chart->setModel(model); // set the model
394  chart->setLabelsColumn(0); // set the column that holds the labels
395  chart->setDataColumn(1); // set the column that holds the data
396 
397  // configure location and type of labels
398  chart->setDisplayLabels(Outside | TextLabel | TextPercentage);
399 
400  // enable a 3D and shadow effect
401  chart->setPerspectiveEnabled(true, 0.2);
402  chart->setShadowEnabled(true);
403 
404  // explode the first item
405  chart->setExplode(0, 0.3);
406 
407  chart->resize(800, 300); // WPaintedWidget must be given an explicit size
408 
409  chart->setMargin(10, Top | Bottom); // add margin vertically
410  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
411 }

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

Generated on Tue Nov 25 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.8