Search code examples
jsonhighcharts

Export chart into a string


I am trying to stringify the whole Highcharts chart object like this:

JSON.stringify(chartObj)

I am getting circular references error. Anyone tried something like this with better luck?


Solution

  • Converting whole chart object to JSON is not possible, since it contains multiple methods and circular references that the JSON.stringify cannot process. If you'd like to convert your chart config to the stringified JSON, you can simply pass chart.userOptions as an argument.

    const chart = Highcharts.chart('container', {
      series: [{
        data: [2, 5, 1, 7, 3, 9]
      }]
    });
    
    const stringifiedChart = JSON.stringify(chart.userOptions);
    console.log(stringifiedChart);
    

    Demo: https://jsfiddle.net/BlackLabel/2571usbg/