繁体   English   中英

高图未执行

[英]Highchart not executed

我已经用highchart绘制了饼图。我得到了ajax响应,但是我的聊天没有执行。我也放了警报,但是alert(“ highchart named”); 直到该行我的所有警报都执行后才执行。我认为options.series [0] .data = responsePIE; 是错误的,但不确定。 我的main12.js代码如下。

$(document).ready(function()
{

    $(function () 
       {

           $('#container').highcharts(
                {
                   chart:
                   {
                        plotBackgroundColor: null,
                        plotBorderWidth: 1,//null,
                        plotShadow: false
                   },
                   title: 
                   {
                        text: 'Browser market shares at a specific website, 2014'
                   },
                   tooltip:
                   {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                   },
                   plotOptions: 
                   {
                        pie: 
                           {
                             allowPointSelect: true,
                             cursor: 'pointer',
                              dataLabels:
                              {
                                enabled: true,
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                                style: 
                                 {
                                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                                 }
                              }
                           }
                     },

        series: [{
            type: 'pie',
            name: 'Browser share',
            data: []
        }]
    });
});

$.getJSON("GetReportdata", function(json) {

    var call11 = JSON.stringify(json);
    alert(call11);
    var responsePIE = jQuery.parseJSON(call11);
    alert(responsePIE[1].title);

    options.series[0].data = responsePIE;
    alert("highchart called");

    var chart = new Highcharts.Chart(options);
});


        });

我的jsp代码如下。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="../css/demo.css" rel="stylesheet">
<script src="../js/jquery.js"></script>
<script src="../external js/jquery-1.9.1.js"></script> 
<script src="../external js/jquery-ui.js"></script>


</head>
<body>



<script src="../js/highcharts.js"></script>
<script src="../js/exporting.js"></script>
<script src="../js/main12.js"></script>



<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
<div id="container2" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>



</body>
</html>

谢谢

看起来这行是错误的:

options.series[0].data = responsePIE;

因为您还没有定义选项。

将选项变量设置为完整的图表定义,然后在getJson回调中创建图表,或者先创建图表,然后使用series setData()方法在http:// getJson回调中的现有图表上设置系列数据( http:/ /api.highcharts.com/highcharts#Series.setData )。

您的脚本应如下所示:

<script type="text/javascript">
$(function () {

    var chart2;


        $.getJSON("pie.json", function(json2) {

    chart2 = new Highcharts.Chart({
      chart: {
        type:'pie',
        renderTo: 'container2',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false
      },
      title: {
        text: 'Interactive Pie'
      },
      tooltip: {
        formatter: function() {
          return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
        }
      },
      plotOptions: {
        pie: {
          allowPointSelect: true,
          cursor: 'pointer',
          dataLabels: {
            enabled: false
          },
          showInLegend: true
         }
      },
      series: [{
        type: 'pie',
        name: 'Browser share',
        data: json2
      }]

  });


});
});
        </script>

和json数据格式: [["chrome",15],["firefox",20],["Android",26],["safari",6]]

在饼图中查看下钻

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM