Creating graphs with JSON and Highcharts [closed]

4

I'm trying to use a simple example provided by Highcharts for creating a chart, but I'm not succeeding.

HTML

<!DOCTYPE HTML>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Highcharts Example</title>

      <script src="http://code.highcharts.com/highcharts.js"></script><scriptsrc="http://code.highcharts.com/modules/exporting.js"></script>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><scripttype="text/javascript">

        $(document).ready(function() {

        var options = {
        chart: {
            renderTo: 'container',
            type: 'spline'
        },
        series: [{}]
        };

        $.getJSON('data.json', function(data) {
        options.series[0].data = data;
        var chart = new Highcharts.Chart(options);
        });

    });
</script>
</head>
<body>

    <div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>

</body>
</html>

data.json

[
[1,12],
[2,5],
[3,18],
[4,13],
[5,7],
[6,4],
[7,9],
[8,10],
[9,15],
[10,22]
]

My question is: why is not the chart created? If I wanted to change the format to [{"a","b"}] how should I change the data passing to the chart?

    
asked by anonymous 09.12.2014 / 13:57

1 answer

0

I tested your HTML and what seemed to be the problem that did not create the chart is that the Highcharts library seems to have a dependency on jQuery, and jQuery is being declared only after Highcharts. Try changing to the following order:

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><scriptsrc="http://code.highcharts.com/highcharts.js"></script>
  <script src="http://code.highcharts.com/modules/exporting.js"></script>
    
10.12.2014 / 00:56