HighCharts not updating when the state changes in React
Im working on a quick program that takes data from an enzyme reaction and plots it to a graph. Im running into this issue where my highcharts component will not update if i pass data to it in props. I can see that the data in state is changing in the console but i dont see anything on the chart.
The Graph component:
class HighGraph extends Component {
state = {
title: {
text: "My chart"
},
series: [
{
data: [1, 2, 3]
}
]
};
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.state.series[0].data = _this.props.list;
}, 2000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>
<HighchartsReact highcharts={Highcharts} options={this.state} />
</div>
);
}
}
export default HighGraph;
the way im passing in the props:
<div>
<HighGraph list={this.state.graphdata} />
</div>
The array being passed:
[0.003, 0.006, 0, 0, 0.003, 0.006, 0.006, 0, 0.003, 0.006, 0.003, 0.003, 0.006, 0.006, 0.006, 0.006, 0.006, 0.006, 0.003, 0, 0.003, 0.003, 0.006, 0.003, 0.003, 0.003, 0.006, 0.003, 0.01, 0.006, 0, 0.003, 0.003, 0.003, 0.003, 0.003, 0.006, 0.003, 0, 0.006, 0.006]
Any Ideas? I still see 1,2,3 in the chart regardless even though the console tells me the state has changed
javascript reactjs highcharts react-highcharts
add a comment |
Im working on a quick program that takes data from an enzyme reaction and plots it to a graph. Im running into this issue where my highcharts component will not update if i pass data to it in props. I can see that the data in state is changing in the console but i dont see anything on the chart.
The Graph component:
class HighGraph extends Component {
state = {
title: {
text: "My chart"
},
series: [
{
data: [1, 2, 3]
}
]
};
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.state.series[0].data = _this.props.list;
}, 2000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>
<HighchartsReact highcharts={Highcharts} options={this.state} />
</div>
);
}
}
export default HighGraph;
the way im passing in the props:
<div>
<HighGraph list={this.state.graphdata} />
</div>
The array being passed:
[0.003, 0.006, 0, 0, 0.003, 0.006, 0.006, 0, 0.003, 0.006, 0.003, 0.003, 0.006, 0.006, 0.006, 0.006, 0.006, 0.006, 0.003, 0, 0.003, 0.003, 0.006, 0.003, 0.003, 0.003, 0.006, 0.003, 0.01, 0.006, 0, 0.003, 0.003, 0.003, 0.003, 0.003, 0.006, 0.003, 0, 0.006, 0.006]
Any Ideas? I still see 1,2,3 in the chart regardless even though the console tells me the state has changed
javascript reactjs highcharts react-highcharts
add a comment |
Im working on a quick program that takes data from an enzyme reaction and plots it to a graph. Im running into this issue where my highcharts component will not update if i pass data to it in props. I can see that the data in state is changing in the console but i dont see anything on the chart.
The Graph component:
class HighGraph extends Component {
state = {
title: {
text: "My chart"
},
series: [
{
data: [1, 2, 3]
}
]
};
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.state.series[0].data = _this.props.list;
}, 2000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>
<HighchartsReact highcharts={Highcharts} options={this.state} />
</div>
);
}
}
export default HighGraph;
the way im passing in the props:
<div>
<HighGraph list={this.state.graphdata} />
</div>
The array being passed:
[0.003, 0.006, 0, 0, 0.003, 0.006, 0.006, 0, 0.003, 0.006, 0.003, 0.003, 0.006, 0.006, 0.006, 0.006, 0.006, 0.006, 0.003, 0, 0.003, 0.003, 0.006, 0.003, 0.003, 0.003, 0.006, 0.003, 0.01, 0.006, 0, 0.003, 0.003, 0.003, 0.003, 0.003, 0.006, 0.003, 0, 0.006, 0.006]
Any Ideas? I still see 1,2,3 in the chart regardless even though the console tells me the state has changed
javascript reactjs highcharts react-highcharts
Im working on a quick program that takes data from an enzyme reaction and plots it to a graph. Im running into this issue where my highcharts component will not update if i pass data to it in props. I can see that the data in state is changing in the console but i dont see anything on the chart.
The Graph component:
class HighGraph extends Component {
state = {
title: {
text: "My chart"
},
series: [
{
data: [1, 2, 3]
}
]
};
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.state.series[0].data = _this.props.list;
}, 2000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>
<HighchartsReact highcharts={Highcharts} options={this.state} />
</div>
);
}
}
export default HighGraph;
the way im passing in the props:
<div>
<HighGraph list={this.state.graphdata} />
</div>
The array being passed:
[0.003, 0.006, 0, 0, 0.003, 0.006, 0.006, 0, 0.003, 0.006, 0.003, 0.003, 0.006, 0.006, 0.006, 0.006, 0.006, 0.006, 0.003, 0, 0.003, 0.003, 0.006, 0.003, 0.003, 0.003, 0.006, 0.003, 0.01, 0.006, 0, 0.003, 0.003, 0.003, 0.003, 0.003, 0.006, 0.003, 0, 0.006, 0.006]
Any Ideas? I still see 1,2,3 in the chart regardless even though the console tells me the state has changed
javascript reactjs highcharts react-highcharts
javascript reactjs highcharts react-highcharts
asked Jan 20 at 0:06
AndreAndre
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If you don't call the this.setState()
method, React will not trigger a re-render with the new data.
Try changing the line in your componentDidMount
.
It'll look something like this:
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.setState({ series: [{ data: _this.props.list }] });
}, 2000);
}
add a comment |
In your HighchartsReact component, you need to supply a prop called oneToOne
and set it to true
.
<HighchartsReact highcharts={Highcharts} options={this.state} oneToOne={true} />
This tells the component to re-render when new data is present by way of State or Prop data.
ref: https://api.highcharts.com/class-reference/Highcharts.Chart#update
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272467%2fhighcharts-not-updating-when-the-state-changes-in-react%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you don't call the this.setState()
method, React will not trigger a re-render with the new data.
Try changing the line in your componentDidMount
.
It'll look something like this:
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.setState({ series: [{ data: _this.props.list }] });
}, 2000);
}
add a comment |
If you don't call the this.setState()
method, React will not trigger a re-render with the new data.
Try changing the line in your componentDidMount
.
It'll look something like this:
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.setState({ series: [{ data: _this.props.list }] });
}, 2000);
}
add a comment |
If you don't call the this.setState()
method, React will not trigger a re-render with the new data.
Try changing the line in your componentDidMount
.
It'll look something like this:
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.setState({ series: [{ data: _this.props.list }] });
}, 2000);
}
If you don't call the this.setState()
method, React will not trigger a re-render with the new data.
Try changing the line in your componentDidMount
.
It'll look something like this:
componentDidMount() {
let _this = this;
_this.interval = setInterval(function() {
console.log(_this.state.series[0].data);
_this.setState({ series: [{ data: _this.props.list }] });
}, 2000);
}
answered Jan 20 at 1:18
d4vsanchezd4vsanchez
3891215
3891215
add a comment |
add a comment |
In your HighchartsReact component, you need to supply a prop called oneToOne
and set it to true
.
<HighchartsReact highcharts={Highcharts} options={this.state} oneToOne={true} />
This tells the component to re-render when new data is present by way of State or Prop data.
ref: https://api.highcharts.com/class-reference/Highcharts.Chart#update
add a comment |
In your HighchartsReact component, you need to supply a prop called oneToOne
and set it to true
.
<HighchartsReact highcharts={Highcharts} options={this.state} oneToOne={true} />
This tells the component to re-render when new data is present by way of State or Prop data.
ref: https://api.highcharts.com/class-reference/Highcharts.Chart#update
add a comment |
In your HighchartsReact component, you need to supply a prop called oneToOne
and set it to true
.
<HighchartsReact highcharts={Highcharts} options={this.state} oneToOne={true} />
This tells the component to re-render when new data is present by way of State or Prop data.
ref: https://api.highcharts.com/class-reference/Highcharts.Chart#update
In your HighchartsReact component, you need to supply a prop called oneToOne
and set it to true
.
<HighchartsReact highcharts={Highcharts} options={this.state} oneToOne={true} />
This tells the component to re-render when new data is present by way of State or Prop data.
ref: https://api.highcharts.com/class-reference/Highcharts.Chart#update
answered Jan 21 at 13:44
clint_milnerclint_milner
196315
196315
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272467%2fhighcharts-not-updating-when-the-state-changes-in-react%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown