Javascript HighCharts仅显示标题
我一整天都在研究这个HighCharts示例,但没能让它全部正常工作。我将显示在getJSON调用中检索的几个数据系列。图表被放入其container DIV中,但没有绘制数据,javascript控制台上也没有错误 我认为问题一定出在JSONP调用格式上,但我看不出有任何问题。JSONP服务在这里:Javascript HighCharts仅显示标题,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我一整天都在研究这个HighCharts示例,但没能让它全部正常工作。我将显示在getJSON调用中检索的几个数据系列。图表被放入其container DIV中,但没有绘制数据,javascript控制台上也没有错误 我认为问题一定出在JSONP调用格式上,但我看不出有任何问题。JSONP服务在这里:http://199.38.183.107/ow/fludata.php?callback=? <html> <head> <title>Demonstratio
http://199.38.183.107/ow/fludata.php?callback=?
<html>
<head>
<title>Demonstration of web service</title>
<style type="text/css">
.chart-container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container" style="width: 100%; height: 400px;"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"> </script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script>
$(function () {
$.getJSON('http://199.38.183.107/ow/fludata.php?callback=?', function(data){
$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: 'Weekly influenza infection counts'
},
subtitle: {
text: 'Data series show the CDC Regions'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Number of infections reported'
},
min: 0
},
plotOptions: {
series: {
marker: {enabled: false},
turboThreshold: 1000000,
states: {hover: {enabled: false}}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+ Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m';
}
},
series: data,
credits: { enabled: false }
}); //container
}); //getJSON
}); //function
web服务演示
.图表容器{
宽度:100%;
身高:100%;
}
$(函数(){
$.getJSON('http://199.38.183.107/ow/fludata.php?callback=?,函数(数据){
$(“#容器”)。高图({
图表:{
类型:“样条线”
},
标题:{
正文:“每周流感感染计数”
},
副标题:{
文本:“数据系列显示CDC区域”
},
xAxis:{
键入:“日期时间”,
dateTimeLabelFormats:{//不显示虚拟年份
月份:'%e.%b',
年份:'%b'
}
},
亚克斯:{
标题:{
文本:“报告的感染人数”
},
最低:0
},
打印选项:{
系列:{
标记:{enabled:false},
阈值:1000000,
状态:{hover:{enabled:false}}
}
},
工具提示:{
格式化程序:函数(){
返回'+this.series.name+'
'+Highcharts.dateFormat('%e.%b',this.x)+':'+this.y+'m';
}
},
系列:数据,
信用证:{已启用:错误}
});//容器
});//获取JSON
}); //功能
我认为url中的json数据格式可能不适合高端图表。尝试在getJSON函数中包含onError函数并检查错误。问题在于日期/时间。你应该用1000乘以你的时间我已经把数据系列包装好了,它们正确地放在花括号里,还有一个外花括号。它应该是一个方括号,因为它返回一个对象数组。谢谢大家的帮助。因此,当您需要通过JSON将包含多个部分(日期和时间,或开始和结束范围)的多个系列发送到Highcharts时,您需要:
[{name:my1stSeries, data:[[1,2],[3,4],...,[m,n]]},{name:my2ndSeries, data:[[5,6],[7,8],...,[o,p]])]
您的JSON有几个错误,请在这里检查它,它是带有jQuery“?”函数回调的JSONP。它通常不会使用JSLint进行解析,但这可能是问题的一部分。编辑:我尝试了你的建议,在没有回调的情况下将其转换为JSON,得到了相同的结果。这也是事实。谢谢