Bug with Stacked Barchart using Moment.js
I'm filling a React model with some dummy data in order to model a Barchart that simulates the %of success every day. This is the code I have:
render() {
const checked = [
{ x: moment().subtract(5, 'days').valueOf(), y: 5 },
{ x: moment().subtract(4, 'days').valueOf(), y: 8 },
{ x: moment().subtract(3, 'days').valueOf(), y: 9 },
{ x: moment().subtract(2, 'days').valueOf(), y: 4 },
{ x: moment().subtract(1, 'days').valueOf(), y: 10 },
{ x: moment().valueOf(), y: 7 },
];
const notChecked = [
{ x: moment().subtract(5, 'days').valueOf(), y: 2 },
{ x: moment().subtract(4, 'days').valueOf(), y: 5 },
{ x: moment().subtract(3, 'days').valueOf(), y: 0 },
{ x: moment().subtract(2, 'days').valueOf(), y: 3 },
{ x: moment().subtract(1, 'days').valueOf(), y: 1 },
{ x: moment().valueOf(), y: 2 },
];
return (
<div>
<XYPlot
margin={{ bottom: 70 }}
xType="time"
width={400}
height={400}
stackBy="y"
>
<VerticalGridLines />
<HorizontalGridLines />
<XAxis tickLabelAngle={-45} />
<YAxis />
<VerticalBarSeries
data={checked}
color="#14fc1b"
/>
<VerticalBarSeries
data={notChecked}
color="#767c76"
/>
</XYPlot>
</div>
);
}
The problem is that the result is completely different each time I refresh the component. Here are some examples where the first chart is the correct one:



What could be wrong?
I have this exact same issue. Perhaps it has something to do with the mutability of moment?
Disregard my last comment. This has nothing to do with moment. I have this issue as well with different types of x-scales.
Silly Question - Did you validate that checked and notChecked aren't changing after you refresh the browser? just from looking at the code, you call moment() over and over, where each call result in differenet results as time goes by, so I'm not sure how react-vis handles such time-span data. another aspect might be different parsing and representation of dates.
having said that - it's weird that the coloring is not consistent, the order should be kept between different render AFAIK.
@Lxopato Have you been able to solve this issue?
@JelleBlaauw Yes, but I solved it by parsing the dates I receive from the endpoint i was supposed to connect. This was just dummy data for making a kind of mockup, but if I try to replicate this issue the problem persist, so I'm not sure where the problem is originated.