Javascript 未执行Highchart
我使用highchart绘制饼图。我得到了ajax响应,但我的聊天没有执行。我也发布了警报,但调用了alerthighchart;在执行该行“我的所有警报”之前不会执行。我认为options.series[0]。data=responsePIE;这是错误的,但不确定。 我的main12.js代码如下Javascript 未执行Highchart,javascript,jquery,ajax,jsp,highcharts,Javascript,Jquery,Ajax,Jsp,Highcharts,我使用highchart绘制饼图。我得到了ajax响应,但我的聊天没有执行。我也发布了警报,但调用了alerthighchart;在执行该行“我的所有警报”之前不会执行。我认为options.series[0]。data=responsePIE;这是错误的,但不确定。 我的main12.js代码如下 $(document).ready(function() { $(function () { $('#container').highcharts(
$(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代码如下所示
$(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);
});
});
谢谢看起来这行是错的:
options.series[0].data = responsePIE;
因为您没有定义选项
将选项变量设置为完整图表定义并在getJson回调中创建图表,或者先创建图表,然后使用series setData方法在getJson回调中的现有图表上设置序列数据。您的脚本应该如下所示:
<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]]
您不需要$function{};部分整个过程已经包含在文档就绪实例中。在getJson函数中访问highcharts的方式不正确。检查你的控制台。您可以通过将图表存储在变量中来访问它,例如var myChart=$container.highcharts;然后使用此变量更新它。您的数据是什么样子的?我是说响应变量。