Here, a solution using a different data form is used. In my other example, a fake group is used to change shape after aggregation.
Using a different form of data.
In this case, I do not think that the data form contributes to what you want to do, so in this answer I will change the form. I will try to use a fake group in the second answer.
The series chart accepts one group with multikeys, and the group filters line by line. Since each line contains both the profitability of 2016 and 2017, it is impossible to combine them separately using crossfilter.
So, for this attempt, I divided the records by year of income:
for (var i = 0; i < n; i++) { var id = Math.round(Math.random()), x = Math.random(), store = "Store"+Math.round(Math.random()); data.push({ id: id, i: i, x: x, store_name: store, earnings_year: 2016, earnings: Math.random()*80 }); data.push({ id: id, i: i, x: x, store_name: store, earnings_year: 2017, earnings: Math.random()*110, }); }
I think this preserves all the qualities of your source data, but it breaks down records by year of income. I also simplified the generation of random numbers .; -)
Now we can easily create a multi-chamber dimension that uses earnings_year .
I donβt think that rounding in the key function of the group worked, because the measurement functions and the key groups should be in the same order , so I moved it:
series = cf.dimension(function(d) { return [d.earnings_year, Math.floor(di / 100.) * 100.]; }),
Now we simply group the same keys and reduce by the amount of earnings instead of x (which, it seems to me, was intended).
series_grouped = series.group() .reduceSum(function(d) { return d.earnings; }),
Fork your violin with filtering by store https://jsfiddle.net/gordonwoodhull/urxLwh81/