Highstock和Highcharts:我如何在同一页面上使用StockChart和饼图

时间:2012-01-16 17:59:51

标签: jquery json highcharts highstock

我对在同一页面上使用highstock stockchart和highcharts饼图感到困惑。在这两种方式中,我使用JSON获取数据。浏览器无法正确呈现Highcharts.StockChart,而呈现Highcharts.Chart类型饼。

以下是我使用的代码段:

<script type="text/javascript">
$("document").ready(function() {
$.getJSON('http://localhost:3000/reports/hits?callback=?', function(data) {
     var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container'
        },
        ...
        },
        series: [{
            name: 'Name',
            data: data,
            tooltip: {
                yDecimals: 0
            }
        }]
     });
  })

    $.getJSON('http://localhost:3000/reports/daily_hit?callback=?', function(data) {
     var chart = new Highcharts.Chart({
        chart: {
           renderTo: 'container1',
           plotBackgroundColor: null,
           plotBorderWidth: null,
           plotShadow: false
        },
       ...
         series: [{
           type: 'pie',
           name: 'Hit',
           data: data
        }]
     });
  })
 }
);
</script>

2 个答案:

答案 0 :(得分:1)

当我尝试使用Highstock图表和Angular Gauge时,我遇到了同样的问题, 当我尝试重新排列像这样的高质量高图javascript库时,问题就解决了

<script type="text/javascript" src="jQuery/Highcharts/highcharts.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highstock.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highcharts-more.js"></script>

或(如果您不想使用其他图形)

<script type="text/javascript" src="jQuery/Highcharts/highcharts.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highstock.js"></script>

我希望它有用

答案 1 :(得分:0)

解决方案很简单,首先是highstock,然后是highchart,如下所示:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highstock.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highcharts.js"></script>
<script type="text/javascript" src="jQuery/Highcharts/highcharts-more.js"></script>

别忘了把jQuery !!

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

这解决了我的问题,希望可以帮到你