简体   繁体   English

HighCharts仅显示标题

[英]HighCharts is only displaying the Title

I've been working through this HighCharts example all day and haven't been able to make it all work. 我整天都在研究这个HighCharts示例,并且无法完成所有工作。 I'm displaying several data series that are retrieved in a getJSON call. 我正在显示几个在getJSON调用中检索的数据系列。 The chart gets put into its container DIV, but there's no data drawn, and no errors on the javascript console. 图表被放入其容器DIV中,但没有绘制数据,并且javascript控制台上没有错误。

I think the problem must be in the JSONP call formatting, but I can't see any problems with it. 我认为问题必须在JSONP调用格式中,但我看不出它有任何问题。 The JSONP service is here: http://199.38.183.107/ow/fludata.php?callback=? JSONP服务在这里: http://199.38.183.107/ow/fludata.php?callback=?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

Problem is in your date/time. 问题在于您的日期/时间。 You should multiply your times with 1000 你应该把你的时间乘以1000

I had wrapped the data series, which were properly in curly brackets, with an outer curly bracket. 我已经包装了数据系列,这些数据系列是正确的大括号,带有一个外部花括号。 It should be a square bracket since it's returning an array of objects. 它应该是一个方括号,因为它返回一个对象数组。 Thanks for the help folks. 谢谢你们的帮助。 So when you need to send multiple series that have multiple parts (date and time, or a start and end range) to Highcharts through JSON, you want: 因此,当您需要通过JSON向Highcharts发送多个具有多个部分(日期和时间,或者开始和结束范围)的系列时,您需要:

[{name:my1stSeries, data:[[1,2],[3,4],...,[m,n]]},{name:my2ndSeries, data:[[5,6],[7,8],...,[o,p]])]

I think the json data from the url may be not in the right format for the High Charts. 我认为来自网址的json数据可能不是High Charts的正确格式。 Try to include the onError function on the getJSON function and check the error. 尝试在getJSON函数中包含onError函数并检查错误。

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

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