Wt examples: PieExample Class Reference

Wt examples 3.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
PieExample Class Reference
Charts example

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

`#include <ChartsExample.h>`

Inheritance diagram for PieExample:
[legend]

List of all members.

## Public Member Functions
| PieExample (Wt::WContainerWidget *parent)
| Creates the pie chart example.

## 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.

                                                  :
      WContainerWidget(parent)
    {
      new WText(WString::tr("pie chart"), this);

      WStandardItemModel *model = new WStandardItemModel(this);

      //headers
      model->insertColumns(model->columnCount(), 2);
      model->setHeaderData(0, WString("Item"));
      model->setHeaderData(1, WString("Sales"));

      //data
      model->insertRows(model->rowCount(), 6);
      int row = 0;
      model->setData(row, 0, WString("Blueberry"));
      model->setData(row, 1, 120);
      // model->setData(row, 1, WString("Blueberry"), ToolTipRole);
      row++;
      model->setData(row, 0, WString("Cherry"));
      model->setData(row, 1, 30);
      row++;
      model->setData(row, 0, WString("Apple"));
      model->setData(row, 1, 260);
      row++;
      model->setData(row, 0, WString("Boston Cream"));
      model->setData(row, 1, 160);
      row++;
      model->setData(row, 0, WString("Other"));
      model->setData(row, 1, 40);
      row++;
      model->setData(row, 0, WString("Vanilla Cream"));
      model->setData(row, 1, 120);
      row++;

      //set all items to be editable and selectable
      for (int row = 0; row < model->rowCount(); ++row)
        for (int col = 0; col < model->columnCount(); ++col)
          model->item(row, col)->setFlags(ItemIsSelectable | ItemIsEditable);

      WContainerWidget *w = new WContainerWidget(this);
      WTableView* table = new WTableView(w);

      table->setMargin(10, Top | Bottom);
      table->setMargin(WLength::Auto, Left | Right);
      table->setSortingEnabled(true);
      table->setModel(model);
      table->setColumnWidth(1, 100);
      table->setRowHeight(22);

      if (WApplication::instance()->environment().ajax()) {
        table->resize(150 + 100 + 14, 20 + 6 * 22);
        table->setEditTriggers(WAbstractItemView::SingleClicked);
      } else {
        table->resize(150 + 100 + 14, WLength::Auto);
        table->setEditTriggers(WAbstractItemView::NoEditTrigger);
      }

      /*
       * Create the pie chart.
       */
      WPieChart *chart = new WPieChart(this);
      chart->setModel(model);       // set the model
      chart->setLabelsColumn(0);    // set the column that holds the labels
      chart->setDataColumn(1);      // set the column that holds the data

      // configure location and type of labels
      chart->setDisplayLabels(Outside | TextLabel | TextPercentage);

      // enable a 3D and shadow effect
      chart->setPerspectiveEnabled(true, 0.2);
      chart->setShadowEnabled(true);

      // explode the first item
      chart->setExplode(0, 0.3);

      chart->resize(800, 300); // WPaintedWidget must be given an explicit size

      chart->setMargin(10, Top | Bottom);            // add margin vertically
      chart->setMargin(WLength::Auto, Left | Right); // center horizontally
    }

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

- /home/koen/project/wt/public-git/wt/examples/charts/ChartsExample.h
- /home/koen/project/wt/public-git/wt/examples/charts/ChartsExample.C