CodeYellowBV / chartist-plugin-legend

Legend plugin for Chartist.js.
https://codeyellowbv.github.io/chartist-plugin-legend/
Other
116 stars 62 forks source link

Variable series revert to their old values on hiding a line #60

Open badrAZ opened 5 years ago

badrAZ commented 5 years ago

Hi!

I've got an issue with the plugin. The series revert to their old values on hiding a line. Please see the example bellow.

class Test extends React.Component {
  state = {
    series: [
      { name: 'Money A', data: [60000, 40000, 80000, 70000] },
      { name: 'Money B', data: [40000, 30000, 70000, 65000] },
      { name: 'Money C', data: [8000, 3000, 10000, 6000] },
      { name: 'Money D', data: [15000, 80000, 60000, 40000] },
      { name: 'Money E', data: [80000, 60000, 40000, 20000] },
    ],
  }

  _onClick = () => {
    this.setState({
      series: [
        { name: 'Money A', data: [40000, 40000, 40000, 40000] },
        { name: 'Money B', data: [40000, 40000, 40000, 40000] },
        { name: 'Money C', data: [40000, 40000, 40000, 40000] },
        { name: 'Money D', data: [40000, 40000, 40000, 40000] },
        { name: 'Money E', data: [40000, 40000, 40000, 40000] },
      ],
    })
  }

  render() {
    return (
      <div>
        <ChartistGraph
          type='Line'
          data={{
            series: this.state.series,
            labels: [
              'First quarter of the year',
              'Second quarter of the year',
              'Third quarter of the year',
              'Fourth quarter of the year',
            ],
          }}
          options={{
            width: '100%',
            height: '300px',
            fullWidth: true,
            chartPadding: {
              right: 40,
            },
            plugins: [ChartistLegend({})],
          }}
        />
      <Button onClick={this._onClick}>
        click
      </Button>
     </div>
    )
  }