我正在准备来自 Google Charts 的数据,但无法为 Google Chart 创建格式化数据数组。
我有以下格式的对象数组:
[
{
"total_amount": 6572.67,
"o_date": "2020-06-01",
"storeName": "Store1"
},
{
"total_amount": 314.21,
"o_date": "2020-06-01",
"storeName": "Store2"
},
{
"total_amount": 5550.34,
"o_date": "2020-06-02",
"storeName": "Store1"
},
{
"total_amount": 461.87,
"o_date": "2020-06-02",
"storeName": "Store2"
},
{
"total_amount": 6471.37,
"o_date": "2020-06-03",
"storeName": "Store1"
},
{
"total_amount": 547.99,
"o_date": "2020-06-03",
"storeName": "Store2"
},
]
Google Chart 需要以下格式的数据:
['Store', 'Store1', 'Store2', { role: 'annotation' } ],
['2020-06-01', 6572.67, 314.21, ''],
['2020-06-02', 5550.34, 461.87, ''],
['2020-06-03', 6471.37, 547.99, '']
我尝试了不同的方法在 foreach 循环中创建新数组,但无法格式化该数组。有人可以建议我正确的方法吗?谢谢。
慕田峪7331174