Here is a glimpse of my dataset:
var items = [
{name: "X", duration: 1, quantity: 2},
{name: "X", duration: 2, quantity: 1},
{name: "Y", duration: 1, quantity: 4},
{name: "X", duration: 3, quantity: 1},
{name: "Y", duration: 1, quantity: 1},
];
Using dc.js, I'm attempting to construct a scatter plot that aggregates the sum of both values (duration and quantity) based on the item's name. In this scenario, I expect the scatter plot to display only two data points, depicted like so:
https://i.sstatic.net/oSUNi.png
I suspect there might be an issue with either the dimension or group setup because none of my points are showing up on the plot.
var cf = crossfilter(items),
dim = cf.dimension(d => d.name),
grp = dim.group().reduce(
(previousValue, currentValue) => [ previousValue[0] + currentValue.duration, previousValue[1] + currentValue.quantity ],
(previousValue, currentValue) => [ previousValue[0] - currentValue.duration, previousValue[1] - currentValue.quantity ],
() => [0, 0]
);
var chart = dc.scatterPlot("#scatter_plot");
chart
.dimension(dim)
.group(grp)
.x(d3.scaleLinear());
I believe the reduce function is accurate. The output of grp.all()
shows the correct aggregated datasets.
https://i.sstatic.net/Tvzre.png
However, despite this, my plot remains empty as mentioned earlier.