|
#include <Wt/WApplication.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WEnvironment.h>
|
|
#include <Wt/WStandardItemModel.h>
|
|
#include <Wt/WText.h>
|
|
#include <Wt/WVBoxLayout.h>
|
|
#include <Wt/Chart/WPieChart.h>
|
|
|
|
using namespace Wt;
|
|
|
|
#define HAPPY_RESIZING
|
|
|
|
class myApplication : public WApplication
|
|
{
|
|
public:
|
|
myApplication(const WEnvironment &env) : WApplication(env)
|
|
{
|
|
std::unique_ptr<WVBoxLayout> upBoxLayout = std::make_unique<WVBoxLayout>();
|
|
upBoxLayout->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
|
|
|
|
#ifdef HAPPY_RESIZING
|
|
upBoxLayout->addWidget(myPieChart());
|
|
#else
|
|
std::unique_ptr<Wt::WContainerWidget> upContainerPieChart = std::make_unique<Wt::WContainerWidget>();
|
|
Wt::Chart::WPieChart *chart = upContainerPieChart->addWidget(myPieChart());
|
|
chart->resize(800, 300);
|
|
upBoxLayout->addWidget(std::move(upContainerPieChart));
|
|
#endif
|
|
|
|
std::unique_ptr<Wt::WContainerWidget> upContainer = std::make_unique<Wt::WContainerWidget>();
|
|
upContainer->addWidget(std::make_unique<Wt::WText>(""));
|
|
upBoxLayout->addWidget(std::move(upContainer), 1);
|
|
upBoxLayout->setResizable(0);
|
|
|
|
root()->setLayout(std::move(upBoxLayout));
|
|
}
|
|
|
|
private:
|
|
|
|
std::unique_ptr<Wt::Chart::WPieChart> myPieChart()
|
|
{
|
|
auto upModel = std::make_shared<Wt::WStandardItemModel>();
|
|
|
|
upModel->insertColumns(upModel->columnCount(), 2);
|
|
upModel->insertRows(upModel->rowCount(), 6);
|
|
|
|
int row = 0;
|
|
upModel->setData(row, 0, Wt::WString("Blueberry"));
|
|
upModel->setData(row, 1, 120);
|
|
upModel->setData(++row, 0, Wt::WString("Cherry"));
|
|
upModel->setData(row, 1, 30);
|
|
|
|
std::unique_ptr<Wt::Chart::WPieChart> upPieChart = std::make_unique<Wt::Chart::WPieChart>();
|
|
|
|
#ifdef HAPPY_RESIZING
|
|
upPieChart->resize(Wt::WLength(), 300);
|
|
#else
|
|
upPieChart->resize(800, 300);
|
|
#endif
|
|
|
|
upPieChart->setModel(upModel);
|
|
upPieChart->setLabelsColumn(0);
|
|
upPieChart->setDataColumn(1);
|
|
upPieChart->setPerspectiveEnabled(true, 0.2);
|
|
upPieChart->setShadowEnabled(true);
|
|
upPieChart->setExplode(0, 0.3);
|
|
|
|
upPieChart->setDisplayLabels(Wt::Chart::LabelOption::Outside |
|
|
Wt::Chart::LabelOption::TextLabel |
|
|
Wt::Chart::LabelOption::TextPercentage);
|
|
|
|
upPieChart->setMargin(10,
|
|
Wt::Side::Bottom);
|
|
|
|
upPieChart->setMargin(Wt::WLength::Auto,
|
|
Wt::Side::Left |
|
|
Wt::Side::Right);
|
|
|
|
return std::move(upPieChart);
|
|
};
|
|
|
|
};
|
|
|
|
std::unique_ptr<WApplication> createMyApplication(const WEnvironment& env)
|
|
{
|
|
auto app = cpp14::make_unique<myApplication>(env);
|
|
return std::move(app);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, &createMyApplication);
|
|
}
|