2

我正在尝试使用 Jqplot 创建折线图。

我正在像这样在 PHP 中生成一个字符串 -

$retstring = "[['Q2 2011', 3.7813],['Q1 2011', 3.7813],['Q3 2011', 3.9000]],  [['Q2 2011', 3.6563],['Q1 2011', 3.6563],['Q3 2011', 3.5765]]";

从字符串结构中可以看出,我想绘制两条线。

$retstring正在使用简单的 AJAX 将其传递给 JavaScript 函数。当我在 JavaScript 函数中获取此字符串时,如何将其转换为要传递给 JqPlot 的数组?

4

1 回答 1

1

I think your problem is related to the question I have already answered.

Therefore, please check my answer there.

Particularly the code sample, which you will fined towards the bottom of my answer, where you could see how the date you provide could be used.

EDIT: When it goes to the main part of the problem, the decoding bit, do just as @mahok says use the json_decode. I wonder if you actually will not experience problems since, technically the String you have is not a proper JSON. In JSON Strings are wrapped in double quotes ("") not in single once (''). Therefore, you might need to replace them appropriately but other than that the method would do the trick.

I was suspecting that the json_decode could have problem with this encoding and as they say it here, the method will return null in this case, please see example 3.

于 2012-06-17T01:04:06.297 回答