0

我想使用 ajax 更新我的图表,但是 setData 方法需要一个数组,而我只有一个字符串,所以它不起作用。

这是我的代码

$(".chooseService a").click(function() {
                            $("span.currentService").html($(this).html());
                            $.get('http://localhost:8080/dashboard/ws/charge/repartition/jour/'+$(this).html(), 
                                function(data) {
                                    // setData (Array<Mixed> data, [Boolean redraw])
                                    chartDay.series[0].setData(data);
                            });
                        });

数据是一个格式化的字符串,如

 [[1356995280000,183.0],[1356995520000,573.0],[1356995760000,243.0]]

有人有什么想法吗?

4

2 回答 2

1

您可以将 JSON 字符串解析为变量数据。

数据 = JSON.parse(数据);

如果您在使用 JSON 方法时遇到问题:http: //caniuse.com/json

于 2013-02-27T10:47:56.923 回答
0

当您从服务器端返回结果时,您可以将内容格式化为 JSON 类型

header ('Content-type: text / json');
header ('Content-type: application / json');

然后,您可以将此结果转换为正确评估它来自客户端的 javascript。

jQuery.parseJSON (this.responseString);

如果你想要这样的数组可以使用这个参考

于 2013-02-27T10:50:24.023 回答