【问题标题】:HighCharts is only displaying the TitleHighCharts 仅显示标题
【发布时间】:2013-10-31 07:17:31
【问题描述】:

我整天都在研究这个 HighCharts 示例,但无法完成所有工作。我正在显示在 getJSON 调用中检索到的几个数据系列。该图表被放入其容器 DIV 中,但没有绘制数据,javascript 控制台上也没有错误。

我认为问题一定出在 JSONP 调用格式上,但我看不出有任何问题。 JSONP 服务在这里: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

【问题讨论】:

  • 你的 JSON 有几个错误,在这里检查jsonlint.com
  • 它是 JSONP,带有对 jQuery 的回调 '?'功能。它通常不会用 JSLint 解析,但也许这是问题的一部分。编辑:我尝试了你的建议,将其转换为没有回调的 JSON,我得到了相同的结果。

标签: javascript jquery highcharts


【解决方案1】:

问题在于您的日期/时间。你应该乘以 1000

【讨论】:

  • 这也是事实。谢谢!
【解决方案2】:

我已经用大括号将数据系列包裹在大括号中。它应该是一个方括号,因为它返回一个对象数组。感谢各位的帮助。因此,当您需要通过 JSON 将具有多个部分(日期和时间,或开始和结束范围)的多个系列发送到 Highcharts 时,您需要:

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

【讨论】:

    【解决方案3】:

    我认为来自 url 的 json 数据的格式可能不适合 High Charts。尝试在 getJSON 函数中包含 onError 函数并检查错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多