Wt examples 4.7.1
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 ()
 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 ( )

Creates the pie chart example.

Definition at line 352 of file ChartsExample.C.

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

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

Generated on Fri May 6 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.4