Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix Highcharts error #13?

I use highchart so, the user can close and open the chart page and redraw the chart, in some case give me this error, how can I fix it, Thanks Here is my code

 function populateGraph(graph1data1,graph1data2,id,time,bottomText,tickinterval){
$(function () {
  $('#'+id).highcharts({
      chart: {
          type: 'line'
      },
      xAxis: {
        tickWidth: 0,
        categories: ['1,2,3,4']
      },
      yAxis: {
        gridLineColor: '#fff',
          title: {
              text: ''
          },
          labels: {
              formatter: function() {
                  return '';
              }
          }              
      },
      navigation: {
        buttonOptions: {
            enabled: false
        }
    },
      series: [{
          name: 'This ',
          data: [1,2,3,4],
          color: '#1e71ef'     
      }, {
          name: 'Last ',
          data: [5,6,7,8],
          color:'#dfe0e1'
      }]
  });
});
}
}




       function loadOnlineDashboardChannel(channel){
          $.ajax({
          type: "get",
          dataType: 'html',
          data: {},
          url: "/companies/2/online_dashboard_channel",
          success: function(data, status){ 
          var obj = JSON.parse(data);
          var template_data = { 
            measures_list:   
              obj.measures         
          };
          $(function() { 
        var tmplHTML_measures = '{{#measures_list}} <div class="col-lg-11  col-lg-offset-1"><p class="indicator-title gray-bottom-border">{{name}}</br></p><div><p><span class="font30px">{{total}} </span> Total {{name}}<br><span class="green-text">{{increase}}%</span> from last <span class="metric_time"></span></p></div><div class="graph-header"><h3>{{this_interval}} </h3><p>New {{name}}</p><p class="percentage-graph green-text">{{percentag e}}%<p></div><div id={{graph_id}} class="graph"></div> </div>{{/measures_list}}';   
          Handlebars.render = function(tmpl, data){data = data || {};return                                                       Handlebars.compile(tmpl)(data);};  
      $("#template").empty().append(Handlebars.render(tmplHTML_measures,template_data) );
      var data_graph;
      for ( var i = 0; i < obj.measures.length; i++ ) {
        data_graph=obj.measures[i];
                      populateGraph(data_graph.this_interval_detail,data_graph.last_interval_detail,data_graph.graph_id,time,obj.bottom_graph_text,parseInt($('#timeframe-select').find(":selected").attr('interval')) );
      }              
     })


  },
  error: function(error) {

}
});

return this;
};

I use handlebar so in this part in var tmplHTML_measures I create the div, in the for I call the function to draw the chart.

Thanks, I repeat sometimes it works perfectly and sometimes fail give me the error #13

like image 226
Marion Avatar asked Feb 03 '14 19:02

Marion


People also ask

How do I fix Highcharts Error 13?

Highcharts error #13 happens when the DOM element the HighCharts is referencing is not found. Therefore, for you to debug this error, you have to check the DOM element availability before calling the the HighCharts callback function..

What is the latest version of Highcharts?

Highcharts v9. 2.0 (2021-08-18)

How can I tell if Highcharts are loaded?

To determine that chart is fully loaded you can use load event, because load event is invoked when all elements are drown (API reference https://api.highcharts.com/highcharts/chart.events.load). However when you are using series animation this runs in a timeout, then load event is invoked before animation will finish.


2 Answers

For me error was resolved when I placed the calling script after the HTML element.

Like;

<div id="container"></div>

<script>    
Highcharts.chart('container', {
// some script here
});
</script>

Also if you check on high chart site it says:

    This error occurs if the chart.renderTo option is misconfigured so that
Highcharts is unable to find the HTML element to render the chart in.

https://www.highcharts.com/errors/13

like image 77
Aamir Shahzad Avatar answered Oct 07 '22 06:10

Aamir Shahzad


I faced the same error and what I got to know is that Error#13 occurs when HighCharts.js tries to access an element which is not present in the DOM.

How I fixed it? I made sure that the HightCharts method is called only after my targeted element is created in the DOM. Bingo!!!! Everything worked fine.

like image 31
Jay Avatar answered Oct 07 '22 07:10

Jay