简体   繁体   English

在HighCharts中,我无法显示从ajax调用返回的数据

[英]In HighCharts, I Can't display data returned from ajax call

I'm trying to modify this example for my needs: http://goo.gl/DEyGtV 我正在尝试根据需要修改此示例: http : //goo.gl/DEyGtV

I'm making an ajax call which returns an output like this: &label=16:44:31&value=356 我正在进行ajax调用,该调用返回如下输出: &label = 16:44:31&value = 356

I want the label part to be the x axis and value part to be the y axis. 我希望标签部分为x轴,值部分为y轴。 Therefore, I have changed this bit, 因此,我对此进行了更改,

var x = (new Date()).getTime(), // current time
y = Math.random();

with this, 有了这个,

var x;
var y;
$.ajax({
    cache: false,
    url: "http://localhost/pages/ReturnData.aspx",
    success: function (data) {
        var varArr = data.toString().split("&");
        x = varArr[1].split("=")[1];
        y = varArr[2].split("=")[1];
    }
});

Also this bit, 还有一点

series: [{
            name: 'Random data',
            data: (function() {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;

                for (i = -19; i <= 0; i++) {
                    data.push({
                        x: time + i * 1000,
                        y: Math.random()
                    });
                }
                return data;
            })()
        }]

With this: 有了这个:

series: [{
    name: 'Prim',
    data: (function () {
        // generate an array of random data
        var data = [],
        time = (new Date()).getTime(),
        i;
        for (i = -19; i <= 0; i++) {
            var xvar;
            var yvar;
            $.ajax({
                cache: false,
                url: "http://localhost/pages/ReturnData.aspx",
                success: function (data) {
                    var varArr = data.toString().split("&");
                    xvar = varArr[1].split("=")[1];
                    yvar = varArr[2].split("=")[1];
                }
            });
            data.push({
                x: xvar,
                y: yvar
            });
        }
        return data;
    })()
}]

Yet the plot is not drawn. 情节还没有画出来。 I'm perfectly certain that the ajax call returns the data I need. 我完全可以肯定,ajax调用会返回我需要的数据。 Could you point out where i'm going wrong? 您能指出我要去哪里了吗?

Many thanks in advance. 提前谢谢了。

Don't do this in that way, it won't work. 不要那样做,那是行不通的。 First call AJAX, and in callback for it create new chart. 首先调用AJAX,然后在回调中创建新图表。 And don't use AJAX twenty times for the same points. 并且不要对相同的点使用AJAX二十次。

Checkout examples: 结帐示例:

You can use series's update method to update chart data: 您可以使用系列的更新方法来更新图表数据:

$.ajax({
    cache: false,
    url: "http://localhost/pages/ReturnData.aspx",
    success: function (data) {
        // data manipulation here...
        chart.series[0].update({
           data: data
        });
    }
});

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-update/ http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-update/

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

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