无法显示Highchart

时间:2013-05-22 12:14:44

标签: highcharts

我遇到HighChart问题。它还没有显示......但是加载了jquery.js,highcharts.js等等。可能是什么错误?

这是我的代码:

<html>
<head> 
<script language="javascript" type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="../js/jquery-ui-1.9.2.custom.js"></script>
<script src="../js/highcharts.js "></script>
<script type="javascript">

var chart = new Highcharts.Chart({
    chart: {        renderTo: 'container2'    },
    xAxis: {    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] },
    series: [{   data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }]
});

</head>
</script>
<body>
<div id="container2" style="height: 300px; margin-top: 2em"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

你应该在DOM准备就绪后加载图表:

$(function () {
    var chart = new Highcharts.Chart({
        chart: {        renderTo: 'container2'    },
        xAxis: {    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] },
        series: [{   data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }]
    });
});