我有来自我的数据库的数据,我将转换为json,如下所示
[{"name":"partner1","cost":"311328","date":"2013-04-01"},
{"name":"partner1","cost":"363780","date":"2013-04-02"},
{"name":"partner1","cost":"364062","date":"2013-04-03"},
{"name":"partner1","cost":"283128","date":"2013-04-04"},
{"name":"partner1","cost":"322608","date":"2013-04-05"},
{"name":"partner2","cost":"425538","date":"2013-04-01"},
{"name":"partner2","cost":"263670","date":"2013-04-02"},
{"name":"partner2","cost":"213192","date":"2013-04-03"},
{"name":"partner2","cost":"378726","date":"2013-04-04"},
{"name":"partner2","cost":"532698","date":"2013-04-05"}]
如何将这个json数据转换为多系列数据的highcharta标准是最好的?
我的最后一招是对db进行多次查询来构建数据,但我认为它会占用服务器时间资源。
感谢您的帮助。
的问候,
答案 0 :(得分:0)
理想情况下,您将数据转换为如下所示:
{"partner1": [
[Date.UTC(2013,3,1), 311328],
[Date.UTC(2013,3,2), 363780],
...
请注意,Javascript日期函数的月份参数从0(1月)开始。
答案 1 :(得分:0)
首先,你应该使用时间戳作为日期(即Date.UTC()),更多的值应该是数字,而不是字符串。