|
#include <Wt/WApplication>
|
|
#include <Wt/WTimer>
|
|
#include <Wt/WStandardItemModel>
|
|
#include <Wt/WText>
|
|
#include <Wt/WSignal>
|
|
#include <Wt/Chart/WCartesianChart>
|
|
#include <Wt/Chart/WStandardPalette>
|
|
|
|
using namespace Wt;
|
|
|
|
class TestApplication : public WApplication
|
|
{
|
|
public:
|
|
TestApplication(const WEnvironment& env);
|
|
~TestApplication() { }
|
|
|
|
private:
|
|
int palette_ = 0;
|
|
Chart::WCartesianChart *chart_ = nullptr;
|
|
};
|
|
|
|
TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
|
|
{
|
|
setTitle("WCartesianChart Update with ToolTips Test");
|
|
|
|
new WText("<h5>Move mouse over bar to drive errors. Sometimes multiple tool tips display. Sometimes JS error in updateTooltip.</h5>", root());
|
|
|
|
auto chartModel = new WStandardItemModel(1, 2, this);
|
|
|
|
chartModel->setData(chartModel->index(0, 0), 0.0);
|
|
chartModel->setData(chartModel->index(0, 1), 100.0);
|
|
chartModel->setData(chartModel->index(0, 1), "Big Bar", ToolTipRole);
|
|
|
|
chart_ = new Chart::WCartesianChart(Chart::CategoryChart, root());
|
|
chart_->resize(400, 400);
|
|
chart_->setAutoLayoutEnabled();
|
|
chart_->setZoomEnabled();
|
|
chart_->setPanEnabled();
|
|
chart_->setModel(chartModel);
|
|
chart_->setXSeriesColumn(0);
|
|
chart_->addSeries(Chart::WDataSeries(1, Chart::BarSeries));
|
|
chart_->axis(Chart::YAxis).setMinimum(0.0);
|
|
|
|
//setup timer to call updateData() every second
|
|
WTimer *update_timer = new WTimer(this);
|
|
update_timer->setInterval(1000);
|
|
update_timer->timeout().connect(std::bind([this] {
|
|
palette_ = (palette_ + 1) % 3;
|
|
chart_->setPalette(new Chart::WStandardPalette(
|
|
static_cast<Chart::WStandardPalette::Flavour>(palette_)));
|
|
}));
|
|
update_timer->start();
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
|
|
}
|