chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Bug in summing up stacked bars with undefined items in series

Open JanMisker opened this issue 5 years ago • 1 comments

When there are undefined items in the series, the summing of stacked bars goes wrong. I tracked it to this line: https://github.com/gionkunz/chartist-js/blob/e7e78201bffe9609915e5e53cfafa29a5d6c49f9/src/scripts/charts/bar.js#L152

Instead of

return {
    x: prev.x + (curr && curr.x) || 0,
    y: prev.y + (curr && curr.y) || 0
};

It should be

return {
    x: prev.x + ((curr && curr.x) || 0),
    y: prev.y + ((curr && curr.y) || 0)
};

Otherwise whenever curr is undefined, the reduce resets to 0.

JanMisker avatar Jun 18 '20 10:06 JanMisker

Found the same issue here.

BTW, your solution @JanMisker works pretty fine! thanks for submitting a PR 😉

Luisetelo avatar Mar 03 '21 11:03 Luisetelo

Looks like it's been fixed in v1.0.0:

https://github.com/chartist-js/chartist/blob/b431f76f95480841c2f04f4eb1b6c8055a1ce5f5/src/charts/BarChart/BarChart.ts#L34-L40

Arantiryo avatar Sep 17 '22 17:09 Arantiryo