Project

General

Profile

Improvements #12495 » Chart.js-Wt-Implementation.txt

Mark Travis, 07/09/2026 07:46 PM

 
Instructions for including Chart.js c++ wrapper in ReportsAndCharts

Recommended configuration code:

// insert into the *.h file
#include <ReportsAndCharts/WChartJSLibrary.h>
#include <ReportsAndCharts/WChartJSDataSeries.h>
#include <ReportsAndCharts/WChartJSOptions.h>

WChartJSLibrary *chart_; // pointer to unique_ptr
std::unique_ptr<WChartJSDataSeries> targetSeries_; // series specific options
PluginOptions pluginOptions_; // Structs to build settings object
ScalesOptions scalesOptions_; // Structs to build settings object
std::unique_ptr<WChartJSOptions> chartOptions_; // Overall chart options


// insert into the *.cpp file
chart_ = addNew<WChartJSLibrary>(ChartJSType::LINE);
chartOptions_ = std::make_unique<WChartJSOptions>(ChartJSType::LINE);

// fill in these structs with the desired options. If there are multiple
// axis, create a scalesOptions_ struct for each axis.
scalesOptions_.axisOptions.axis = "x";
scalesOptions_.axisOptions.type = "linear";
chartOptions_->setXScales(scalesOptions_); //add the prior struct
// chartOptions_->setYScales
// chartOptions_->setRScales // necessary for bubble charts
pluginOptions_.title.display = true;
pluginOptions_.title.text = chartTitle->text().toUTF8();
pluginOptions_.legend.position = "right";
pluginOptions_.zoomAndPan.wheelEnabled = true;
pluginOptions_.zoomAndPan.pinchEnabled = true;

chartOptions_->setPlugins(pluginOptions_); // add the prior struct (only one needed)

chartOptions_->setResponsive(true);
chartOptions_->setMaintainAspectRatio(false);

targetSeries_ = std::make_unique<WChartJSDataSeries>(ChartJSType::LINE);
targetSeries_->setBorderWidth(3);
targetSeries_->setTension(0.5);
targetSeries_->setIndexAxis("x");
targetSeries_->setPointRadius(0);
targetSeries_->setLineBarCircleSeriesBorderColor("rgba(255, 107, 107, 0.85)");
targetSeries_->setOrder(2);
chart_->addSeries(actualTargetColumnNumber,true,targetSeries_->getJson());


// This is the final two steps before showing the chart
chart_->setOptions(chartOptions_->getOptions());
chart_->buildAndShowChart();

(8-8/9)