3D Category Chart

General info on how to use the 3D Charting API can be found under '3D numerical chart'.

The data

A categorical representation is only possible for grid-based data. In terms of the API this means any class deriving WAbstractGridData. Wt already provides two implementations: WGridData and WEquidistantGridData. To create a categorical chart, the chart must be configured as such (by setting the type to CategoryChart) and the data which is added to this chart must be of the type BarSeries3D.

A categorical chart also allows multiple data series to be shown if the dimensions are the same. The different bar-series are then stacked on top of each other.

#include <Wt/WApplication.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WStandardItemModel.h>
#include <Wt/WCssDecorationStyle.h>
#include <Wt/WBorder.h>
#include <Wt/WImage.h>
#include <Wt/Chart/WCartesian3DChart.h>
#include <Wt/Chart/WGridData.h>

#include "../../treeview-dragdrop/CsvUtil.h"

#include "DataModels.h"

auto container = std::make_unique<WContainerWidget>();

// create the chart
auto chart
    = container->addNew<Chart::WCartesian3DChart>();

// disable server-side rendering fallback; our VPSes don't have that
chart->setRenderOptions(GLRenderOption::ClientSide| GLRenderOption::AntiAliasing);

WCssDecorationStyle style;
style.setBorder(WBorder(BorderStyle::Solid, BorderWidth::Medium,

chart->resize(800, 600);
chart->setTitle("Fish consumption in western Europe");
chart->axis(Chart::Axis::Z3D).setTitle("Consumption (pcs/year)");
chart->setLegendStyle(WFont(), WPen(),
chart->setGridEnabled(Chart::Plane::XZ, Chart::Axis::Z3D, true);
chart->setGridEnabled(Chart::Plane::YZ, Chart::Axis::Z3D, true);

// load data
auto model =
    csvToModel(WApplication::appRoot() + "fish_consumption.csv", false);

// highlight Belgian codfish consumption
for (int i=0; i < model->rowCount(); i++) {
    for (int j=0; j < model->columnCount(); j++) {
        if (asString(model->data(0, j)) == WString("codfish") &&
            asString(model->data(i, 0)) == WString("Belgium"))
            model->setData(i, j,
                           WColor(StandardColor::Cyan), ItemDataRole::MarkerBrushColor);

auto isotopes = std::make_unique<Chart::WGridData>(model);
isotopes->setTitle("made-up data");

// add the dataseries to the chart