JQPlot 图表不显示

JQPlot chart not displaying

查了其他类似的问题,还是查不到问题的根源。

代码如下:

<!DOCTYPE html>
<html>
<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="resources/jquery/jquery.jqplot.js"></script>
<link rel="stylesheet" type="text/css" href="resources/jquery/jquery.jqplot.css" />

</head>
<body>

<div id="chart2" style="height:300px;width:500px; "></div>

</body>

<script type='text/javascript'>

$(document).ready(function() {

   var line1 = [['Nissan', 4],['Porche', 6],['Acura', 2],['Aston Martin', 5],['Rolls Royce', 6]];

    $('#chart2').jqplot([line1], {
        title:'Bar Chart with Varying Colors',
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions: {
                // Set the varyBarColor option to true to use different colors for each bar.
                // The default series colors are used.
                varyBarColor: true
            }
        },
        axes:{
            xaxis:{
                renderer: $.jqplot.CategoryAxisRenderer
            }
        }
    });


});

</script>

</html>

问题是,除了图表 canvas 外,没有显示任何内容。控制台中没有记录任何错误,源文件已加载。我将 .jqplot 的调用移到了 chart2 div 下方,因为用户认为这是必要的,但我认为情况并非如此,因为我们正在使用 $(document).ready(function() ...

知道问题出在哪里吗?

已解决。

需要包含在 .jqplot 调用中指定的附加渲染器。

<script type="text/javascript" src="resources/jquery/plugins/jqplot.barRenderer.js"></script>
<script type="text/javascript" src="resources/jquery/plugins/jqplot.categoryAxisRenderer.js"></script>