通过AJAX与jQuery Flot接收数据 [英] Receive data via AJAX with jQuery Flot

查看:305
本文介绍了通过AJAX与jQuery Flot接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b PHP输出(不是JSON):

  [[1,153],[2,513],[3,644]] ~~ [[1,1553],[2,1903],[3 ,2680]] 

jQuery调用

  $。ajax({
url:'xxx.php',
成功:函数(数据){
var dataArray = data.split('~~'),
dataArray1 = dataArray [0],
dataArray2 = dataArray [1],
plot = $ .plot($('#xxx' ),[{
data:dataArray1,
color:colors [0]
},
{
data:dataArray2,
color:colors [1 ],
points:{
show:true,
}
},
],{
series:{
bars:{
show:true,
barWidth:.6,
align:'center'
}
},
grid:{
show:true,
hoverable:true,
clickable:true,
autoHighlight:true,
borderWidth:true,
borderColor:'rgba(255,255,255,0)'
},
xaxis:{
显示:false
}
});
}
});

以这种方式获取数据,我尝试使用jQuery Flot但不起作用。 。

鉴于,我可以通过分离数据:

第一个标签:

  [[1,153],[2,513],[3,644]] 

第二个标签:

  [[1,1553],[2,1903],[3,2680]] 

解决方案

你已经收到了一个没有被限定为JSON数据的字符串。然后你将它分解为两个字符串,它们仍然不是JSON。然后,您尝试使用 data:your_string_value 实例化 plot 对象。这里 plot 等待一个对象,而不是字符串。
尝试用这种方式定义 data data:$。 parseJSON(dataArray1)


I have a problem with jQuery flot.

PHP output (not JSON):

[[1, 153], [2, 513], [3, 644]] ~~ [[1, 1553], [2, 1903], [3, 2680]]

jQuery call:

$.ajax({
    url: 'xxx.php',
    success: function (data) {
        var dataArray = data.split('~~'),
        dataArray1 = dataArray[0],
        dataArray2 = dataArray[1],
        plot = $.plot($('#xxx'), [{
            data: dataArray1,
            color: colours[0]
        },
        {
            data: dataArray2,
            color: colours[1],
            points: {
                show: true,
            }
        },
        ], {
            series: {
                bars: {
                    show: true,
                    barWidth: .6,
                    align: 'center'
                }
            },
            grid: {
                show: true,
                hoverable: true,
                clickable: true,
                autoHighlight: true,
                borderWidth: true,
                borderColor: 'rgba(255, 255, 255, 0)'
            },
            xaxis: {
                show: false
            }
        });
    }
});

Taking the data in this way, I'm trying to use jQuery Flot but does not work...

Whereas, I can by separating data:

First label:

[[1, 153], [2, 513], [3, 644]]

Second label:

[[1, 1553], [2, 1903], [3, 2680]]

解决方案

You have recieved a string that was not qualified as JSON data. Then you've splitted it on two strings, that are still not JSON. Then you trying to instantiate plot object with data: your_string_value. Here plot waiting of an object, not string. Try to define data of your plot this way: data:$.parseJSON( dataArray1 )

这篇关于通过AJAX与jQuery Flot接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆