Wt examples  3.3.4
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 327 of file ChartsExample.C.

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

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

Generated on Thu Nov 12 2015 for the C++ Web Toolkit (Wt) by doxygen 1.8.9.1