0

我有来自我的数据库的数据,我将其转换为 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标准的最佳方法是什么?

我最后的手段是对数据库进行多次查询来构造数据,但我认为它会消耗服务器时间资源。

感谢您的帮助。

问候,

4

2 回答 2

0

首先,您应该使用时间戳作为日期(即 Date.UTC() ),而且值应该是数字,而不是字符串。

于 2013-05-06T13:16:52.157 回答
0

Ideally you'd transform the data to look like this:

{"partner1": [
  [Date.UTC(2013,3,1), 311328],
  [Date.UTC(2013,3,2), 363780],
...

Note that the month argument to Javascript's Date function starts from 0 (January).

于 2013-05-06T12:15:17.410 回答