Home › forums › Chart Support › How to update indexLabel with label and value.
Tagged: indexLabel pieChart
This is for a pie chart. How do I update the indexLabel when the indexLabel contains both the label and the value? IE – chart.options.data[0].dataPoints[0].indexLabel = ???; In the indexLabel setup I have indexLabel: “{label} {y}”. So if I have a label and a value in the indexLabel, how can I update the value part?
@jeppy7,
You are setting the indexLabel at dataPoint level. Instead, setting it at dataSeries level will work fine in your case. chart.options.data[0].indexLabel = "{label} {y}";
chart.options.data[0].indexLabel = "{label} {y}";
__________ Indranil Deo, Team CanvasJS
That’s almost correct. I was actually able to get it sort of working. I can use either chart.options.data[0].dataPoints[0].indexLabel = “{label} {y}”; or chart.options.data[0].indexLabel = “{label} {y}”; but the only way I can get it to show up is if I call chart.render() again after the change. When I do that I get some weird behavior though. The circle doesn’t redraw very well, etc. Is there any way to get the updated options to show on screen without having to call chart.render()?
You should call chart.render() to render chart once options are set or updated. You can also use set method to achieve the same without calling chart.render() as the method re-renders chart. chart.data[0].set("indexLabel", "{label} {y}");. Note: Chart should be rendered once before you can use set method
chart.data[0].set("indexLabel", "{label} {y}");
When I do that I get some weird behavior though. The circle doesn’t redraw very well, etc.
Can you kindly create jsfiddle reproducing the issue, so that we can understand it better and help you out?
___________ Indranil Deo, Team CanvasJS
You must be logged in to reply to this topic.