gpt4 book ai didi

javascript - Highchart 未执行

转载 作者:行者123 更新时间:2023-11-28 08:04:04 26 4
gpt4 key购买 nike

我使用 highchart 绘制饼图。我收到了 ajax 响应,但我的聊天未执行。我也放置了警报,但警报(“highchart 已调用”);直到该行执行完我的所有警报后才执行。我认为 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 回调中创建图表,或者先创建图表,然后使用系列 setData() 方法在 getJson 回调中的现有图表上设置系列数据( http://api.highcharts.com/highcharts#Series.setData)。

关于javascript - Highchart 未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24996921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com