Highcharts图书馆无法正常工作

时间:2014-03-07 02:05:43

标签: javascript jquery highcharts graphing

我目前只是尝试从highcharts实现这个例子,只是为了感受它并玩转,但它似乎没有用。我尝试加载他们的独立框架,不同版本的jQuery,但图表不会呈现。这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    </head>
<body>
<script type="text/javascript">
var chart = new Highcharts.Chart({
chart: {
    //alignTicks: false,
    type: 'line',
    renderTo: 'container'
},
        $(function () { 
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Fruit Consumption'
        },
        xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
        },
        yAxis: {
            title: {
                text: 'Fruit eaten'
            }
        },
        series: [{
            name: 'Jane',
            data: [1, 0, 4]
        }, {
            name: 'John',
            data: [5, 7, 3]
        }]
    });
});
    </script>
<div id="container" style="width:100%; height:400px;"></div>
</body>
</html>

提前致谢。

2 个答案:

答案 0 :(得分:1)

http://jsfiddle.net/rjreddy78/hgCPa/

<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    </head>
<body>
<script type="text/javascript">
        $(function () { 
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Fruit Consumption'
        },
        xAxis: {
            categories: ['Apples', 'Bananas', 'Oranges']
        },
        yAxis: {
            title: {
                text: 'Fruit eaten'
            }
        },
        series: [{
            name: 'Jane',
            data: [1, 0, 4]
        }, {
            name: 'John',
            data: [5, 7, 3]
        }]
    });
});
    </script>
<div id="container" style="width:100%; height:400px;"></div>
</body>
</html>

答案 1 :(得分:0)

您需要添加

 $(function () { 
   //chart code
 });

$(document).ready(function(){
  //chart code
});