Crazy__st
Crazy__st

Reputation: 13

some error will be printed in consoled when i export highcharts

I want to export highcharts.

I found that chart.exportChart can help me.

it can export a static chart.

But if i use it to export a dynamic chart, a image will be exported and "highcharts.js:285 Uncaught TypeError: Cannot read property 'data' of undefined" will be printed in console.

who can tell me why?

here is an experiment of exporting a dynamic chart:http://jsfiddle.net/u02amghs/

if you click "export chart" , error message will be printed in console.

here is an experiment of exporting a static chart:http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/chart-exportchart-filename/

Upvotes: 1

Views: 264

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

The problem is that you want to add points to the exported chart. When exporting chart, new chart is generated (including chart.events.load callback), exported and then destroyed. setInterval is not cleared and that's why you see that error. And to answer your question, don't add setInterval when chart should be exported:

chart: {
  events: {
    load: function() {

      if (!this.options.chart.forExport) {
        // set up the updating of the chart each second
        var series = this.series[0];
        setInterval(function() {
          var x = (new Date()).getTime(), // current time
            y = Math.random();
          series.addPoint(['Jan', y], true, true);
        }, 1000);
      }
    }
  }
},

options.chart.forExport is inner property, set only when exporting chart.

Upvotes: 1

Related Questions