Open stevewillard opened 9 years ago
One thing I noticed is that in your code responsive: true
which is NOT a chart option. According to Chart.js documentation, we need to set it like: Chart.defaults.global.responsive = true;
globally.
Also, according to React.js documentation, we are not allowed to directly set this.state
. We should use getInitialState()
instead. How about this?
props
from parent component this.props.data
in the component's state using getInitialState()
like
getInitialState: function() { return {{chartData: this.props.data}}; }
I tried setting global.responsive = true, but that doesn't seem to change anything.
I like the idea of providing data through props -- I assume that'll require a pull request?
Please take it easy. You do not need a pull request for that. It is about your implementation. In your code, you place the data using this.state, which is the source of the problem. We cannot directly control state ourselves, React does on our behalf. You have props in your constructor you can pass data by using that props, then inside your component, set it as default state using getInitialState. I'm outside now, I'll try to think of a concrete example later.
Hmm ok, I think I misunderstood what you were originally saying.
I tried passing in some props to this component, and then passing down these props to my react-chartjs
Hey Steve, I just realized rules are a bit different for ES6 from other scripts. I was reading this. My apologies, you were not entirely wrong! I use CoffeeScript so I was just trying to directly translate word by word. Having said that, I wrote something similar to what you were trying to do, selfishly converting everything into CoffeeScript. Then, it works perfectly at the very first rendering. Here is my code with my home made chartjs wrapper:
My code is like a pseudo-code. I hope it will give you some ideas to solve your issues.
Ugh I still can't seem to get this to work. I think this must be a bug with react-chartjs. I'll try to do something similar to your home made chartjs wrapper, I think.
I wish I could look into it further with you but I need to learn the new syntax first ;) I implemented it from scratch but working perfectly on my Rails app. Trust me. Try to translate it in your language. Let me know how it goes, because I want to improve it if necessary. Good luck!
It happened the same here, did you try with?
<Line data={this.state.chartData} options={chartOptions} redraw width="1100" height="150" />
Any update to this? seems a common issue.
oh man I wish I saw this thread earlier, any updates
This should get you up and running
Still an issue, not sure why this was closed
@contra chart.js current version is v2.4.0, react-chartjs peer dependency chart.js is v1.1.1. Downgrade chart.js to version v1.1.1 works well.
Anyone have any idea why my chart doesn't render initially, but if I update the component using the react-hot-loader (webpack), things redraw. This is my component:
I tried throwing on the "redraw" prop but it doesn't seem to help.