wergeld
wergeld

Reputation: 14442

HighCharts Export Breaks After Resetting Chart Options

On initial load of a page we set the chart options and create the chart. We allow the user to manipulate which series items are shown/hidden and also to change what the type of each series is. We also have a "Reset Chart" action that will revert the chart back to its original load setup. Once the user resets the chart any changes made to chart are not reflected on the exported image except if the user has changed their series chart type. An example jsFiddle is here that demonstrates this issue.

After the chart loads click on a export type and you see that they match. Now deselect one of the series from the legend and export again - note that the export and page still match. Now select "single series" from the drop down and export - again they match. Now click on Reset Chart or select "multi series" from the drop down. This brings the chart to the way it looked when it was initially loaded. Now deselect a series and export - they no longer match. The exported image still has all series selected. Now select "single series" again and change the type to "line" and export - again, all series are shown but they are all line type.

This is how I am resetting the chart on the "Reset Chart" click action:

   //reset Main Chart chart to original specs
    resetMainChart.live('click', function () {
        forceResetChart(chartMainLoc);
    });
...
function forceResetChart(chart) {
    if (mainGraphMode.is(':visible')) {
        if (mainGraphMode.val() == 'multiple') {
            //if (mainGraphFormatType.val() != 'null') {
            //    mainGraphFormatType.val('null');
            //}
            mainGraphFormatType.val('null');
        } else {
            mainGraphMode.val('multiple');
            mainGraphFormatType.val('null');
        }
        mainGraphFormatType.hide();
        mainGraphFormatDefault.show();
    } else {
        mainGraphFormatType.val('null');
    }
    $('#chartMain').highcharts().destroy();
    chartMainLoc = new Highcharts.Chart(optionsChartMain, highlightSer);
}

I am at a loss here as to why resetting the chart in this fashion breaks the exporting. I have read some responses to other questions stating that we should get the SVG of the currently displayed chart and send it to the export method. I am not sure how to do that. The docs state that the getSVG() method gets the SVG string of the intially loaded chart - not the active chart.

Upvotes: 0

Views: 855

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

Well, there is nothing wrong, it works exactly as you written. Consider this:

chartMainLoc = new Highcharts.Chart(optionsChartMain, highlightSer);

In highlightSer you are displaying all series. When exporting chart, chart is created from the beginning, and callback is used once again, so all series are visible. Remove highlightSer callback and you will see the difference.

Upvotes: 1

Related Questions