react-vis icon indicating copy to clipboard operation
react-vis copied to clipboard

Bug with Stacked Barchart using Moment.js

Open Lxopato opened this issue 7 years ago • 5 comments

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:

image

image

image

What could be wrong?

Lxopato avatar May 06 '19 17:05 Lxopato

I have this exact same issue. Perhaps it has something to do with the mutability of moment?

JelleBlaauw avatar May 10 '19 10:05 JelleBlaauw

Disregard my last comment. This has nothing to do with moment. I have this issue as well with different types of x-scales.

JelleBlaauw avatar May 10 '19 13:05 JelleBlaauw

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.

talc23 avatar Jun 04 '19 08:06 talc23

@Lxopato Have you been able to solve this issue?

JelleBlaauw avatar Jun 12 '19 08:06 JelleBlaauw

@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.

Lxopato avatar Jun 12 '19 13:06 Lxopato