Project

General

Profile

Feature #1154 ยป hello.C

Pieter Libin, 02/14/2012 09:52 AM

 
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WStandardItemModel>
#include <Wt/WStandardItem>
#include <Wt/Chart/WDataSeries>
#include <Wt/Chart/WCartesianChart>

#include <boost/any.hpp>

using namespace Wt;

class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env);
};

HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
std::vector<int> values;
values.push_back(-20);
values.push_back(-75);
values.push_back(-31);
values.push_back(-48);

int cols = 2;

Chart::WCartesianChart *chart = new Chart::WCartesianChart(root());

WStandardItemModel *model = new WStandardItemModel(values.size(), cols);
for (unsigned i = 0; i < values.size(); ++i) {
model->insertRow(model->rowCount());
model->setData(i, 0, boost::any(i + 1));
model->setData(i, 1, boost::any(values[i]));
}

chart->setModel(model);
chart->setXSeriesColumn(0);

chart->axis(Chart::YAxis).setRange(-100, -10);

for (int i = 1; i < model->columnCount(); ++i) {
Chart::WDataSeries s(i, Chart::BarSeries);
chart->addSeries(s);
}

chart->setType(Chart::CategoryChart);
chart->resize(800, 400);
}

WApplication *createApplication(const WEnvironment& env)
{
return new HelloApplication(env);
}

int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}

    (1-1/1)