Wt examples  3.3.6
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::PieExample ( Wt::WContainerWidget *  parent)

Creates the pie chart example.

Definition at line 338 of file ChartsExample.C.

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

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

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13