Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts - Updating a chart's option after initial render

Tags:

highcharts

Is it possible to update a chart's option (marginRight for example) and call redraw() to have that new value reflected in the chart? Or does a new instance of the chart need to be created for these types of changes?

I think it may be the latter because it sounds like only data or axis values can be altered after the chart is created. I see the documentation for redraw states:

Redraw the chart after changes have been done to the data or axis extremes

And the new dynamic feature in 3.0 states:

Through a full API you can add, remove and modify series and points or modify axes at any time after chart creation.

Thank you in advance.

Update

My reason for wanting to do this was I had a vertical layout and right-aligned legend that was overlapping my chart. I just realized Highcharts automatically sets the correct marginRight to accommodate for this if one isn't explicitly specified.

like image 286
Irving Avatar asked May 21 '13 22:05

Irving


2 Answers

Unfortunately you cannot modify margin parameter dynamically, so you need to destroy old chart and create new instance.

This feature is one of our target in the nearest future.

like image 111
Sebastian Bochan Avatar answered Sep 28 '22 07:09

Sebastian Bochan


Say you got a chart initialized like this:

chart = new Highcharts.Chart({
    ...

You can change trivial attributes, like its title, like this:

chart.setTitle({text: "New title"});

And you can refresh the dataset it's using with a new one, like this:

chart.series[0].setData(newChartData, true);

Where newChartData will contain the array with new data you wish to display

like image 44
Filippos Karapetis Avatar answered Sep 28 '22 06:09

Filippos Karapetis