简体   繁体   English

如何格式化Highcharts columnRange以获得温度Min和Max的json数据

[英]How to format Highcharts columnRange to get json data for temperature Min and Max

I'm trying to display information on Highcharts from the forecast.io api. 我正在尝试通过Forecast.io api在Highcharts上显示信息。 With the help of others on this site, I have figured out how to call the data using a simple line or area chart; 在该站点上其他人的帮助下,我已经找到了如何使用简单的折线图或面积图调用数据的方法。 however, I can't figure out how to with the columnRange chart. 但是,我不知道如何使用columnRange图表。 I want to display the daily min and max temperature forecast. 我想显示每日的最低和最高温度预报。 So the top column would display today's min and max temp, and the next column would be tomorrows, and so on. 因此,第一列将显示今天的最低和最高温度,下一列将是明天,依此类推。

To call the min and max for today from forecast.io: 要从Forecast.io调用今天的最小值和最大值:

  • data.daily.data[0].temperatureMin data.daily.data [0] .temperatureMin
  • data.daily.data[0].temperatureMax data.daily.data [0] .temperatureMax

Tomorrows would have a "1" instead of a 0. The day after would have a "2". 明天将使用“ 1”而不是0。第二天将使用“ 2”。

I haven't been able to figure out how to make a function that does this for each day. 我还没办法弄清楚每天如何做一个能做到这一点的功能。 I have a jsfiddile which includes my forecast.io API key. 我有一个jsfiddile,其中包含我的Forecast.io API密钥。 This is needed to call from the source. 需要从源进行呼叫。

Anyways, any help would be much appreciated! 无论如何,任何帮助将不胜感激! http://jsfiddle.net/nn51895/gjw9m1qo/2/ http://jsfiddle.net/nn51895/gjw9m1qo/2/

(my x axis labels are really messed up as you will see..) (如您所见,我的x轴标签确实弄糟了。)

$(function () {

$('#container').highcharts({

    chart: {
        type: 'columnrange',
        inverted: true
    },

    title: {
        text: ''
    },

    subtitle: {
        text: ''
    },

    xAxis: {

    },

    yAxis: {
        title: {
            text: ''
        }
    },

    tooltip: {
        valueSuffix: '°F'
    },

    plotOptions: {
        columnrange: {
            dataLabels: {
                enabled: true,
                formatter: function () {
                    return this.y + '°F';
                }
            }
        }
    },

    legend: {
        enabled: false
    },

    series: [{
        name: 'Daily Min and Max',
        data: 'ChartData',
        pointStart: new Date().getTime(),
       pointInterval:90000000,

    }]

  });

});

$.ajax({
 url: "https://api.forecast.io/forecast/87a7dd82a91b0b765d2576872f2a3826/53.479324,-2.248485",
 jsonp: "callback",
 dataType: "jsonp",
 success: function(chart) {

  var dataArr = new Array();
   var height = chart.xAxis[0].height;
  var pointRange = chart.daily.data[0].temperatureMax - chart.daily.data[0].temperatureMin;
   var max = chart.daily.data[0].temperatureMax;
   var min = chart.daily.data[0].temperatureMin;
   var pointCount = (max - min) / pointRange;
    var timeint = chart.daily.data[0].time; 
 for(var i=0; i<chart.daily.data.length; i++)
  dataArr.push(chart.daily.data[i].temperatureMin);

 plotChart(dataArr, timeint)


 }
 });

First of all, as said in the comment: 首先,如评论中所述:

success: function (chart) {
    ...
    var height = chart.xAxis[0].height;
}

You are trying to get for some unknown reason height of xAxis from the chart. 由于某种未知原因,您试图从图表中获取xAxis的高度。 Meanwhile you chart variable is referring to the data from AJAX call. 同时,您的chart变量引用的是来自AJAX调用的数据。 I hope that's clear, so remove that line or change to: 我希望这很清楚,因此删除该行或更改为:

success: function (chart) {

    var myChart = $('#container').highcharts();
    var dataArr = new Array();
    var height = myChart.xAxis[0].height;
}

Second thing, that option: 第二件事,那个选择:

        data: 'ChartData',

Is wrong, there should be an empty array, since Highcharts requires array for data, not some string: 是错误的,应该有一个空数组,因为Highcharts需要数组来存储数据,而不是一些字符串:

        data: [],

Now, after fixing these bugs, you should go to this demo and create the same data format. 现在,修复这些错误之后,您应该转到此演示并创建相同的数据格式。 That's example for required format for Highcharts. 这是Highcharts所需格式的示例。

More about series.data can be found in API reference - you need to read this. 可以在API参考中找到有关series.data更多信息-您需要阅读此内容。

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

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