-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hiding a line is not persistent with data changes #48
Comments
I'm afraid I can't follow, what is the expected result? I'm not sure what exactly you are doing and am not sure if this is intended or not, since i assume you are switching references or something.. Please elaborate and include your code so i can investigate. |
Hi! I'll try to be clearer. Here's my code for the 2 line example: Codeimport React, { Component } from 'react'
import ChartistGraph from 'react-chartist'
import ChartistLegend from 'chartist-plugin-legend'
const DATA1 = {
series: [
[0, 2],
[1, 1]
]
}
const DATA2 = {
series: [
[0, 2],
[1, 1]
]
}
export default class extends Component {
state = {
data: DATA1
}
_switch = () => this.setState({
data: this.state.data === DATA1
? DATA2
: DATA1
})
render () {
const opts = {
showArea: true,
height: 300,
plugins: [
ChartistLegend()
]
}
return <div>
<button onClick={this._switch}>Switch data set</button>
<div>
<ChartistGraph
type='Line'
data={this.state.data}
options={opts}
/>
</div>
</div>
}
} And here's a more concrete example to help you understand what my issue is: I'm injecting some network stats into a chartist graph: The stats are updated every 10 seconds by injecting a new data set. But a few seconds later, on the next data update, the line shows up again: The expected result would be for the red line to stay hidden until I check the box again. I hope I've made myself clear :) |
All clear now, I agree with you, that should not happen. You might have already seen by the amount of open issues, I'm very, very busy with things besides maintaining this project, so my throughput is really low right now. I'll try to find some time soon. |
What happens after looking at the code is quite straightforward. Legend is called at initialization of plugin. Clicking a series element will remove it from the chart data entirely. So updating the chart data will override whatever the plugin has done until now. Worse, after clicking on the legend you will get old data instead of new data because at initialization it took the data. Even worse, there is no way to access the plugin variables to manually update them. The plugin should get called on data updates or something. In reality Chartist should allow you to change data and have properties for data like "visible:false" to avoid this entire mess. Currently (horrible workaround), I check legend elements if they are hidden, recreate chart from scratch and "click" the legend items through javascript, there is a flicker of course.
|
Hello, |
If somebody still got issue like me, when you cannot have legend while updating data, here is my solution. 4 years later woow. In CSS add class: In JS remove all references to originalSeries and seriesCopy (line 97, 183, 192, 202). Edited/added lines 155, 161, 171, 175.
It has one dis/advantage - depending how you watch on it. Anyway now you can update data and chart:
Maybe somebody will use just idea and make the code looks better :) |
I have 2 data sets:
Note: the 2 data sets contain the same values but are not the same object.
I inject one of them in a
Chartist
which draws this chart:Then I hide the blue line by unchecking the box:
Then I dynamically inject the other set by clicking the "Switch data set" button:
The blue line shows again.
The text was updated successfully, but these errors were encountered: