Irving
Irving

Reputation: 1267

Highcharts - Updating a chart's option after initial render

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.

Upvotes: 5

Views: 12880

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37578

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.

Upvotes: 4

Filippos Karapetis
Filippos Karapetis

Reputation: 4652

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

Upvotes: 2

Related Questions