作者:金燁欣_973 | 来源:互联网 | 2023-10-12 21:52
Ihavefollowingjsonarraywhichisgeneratedatruntime.Hencethenumberofnamedatapairsvarie
I have following json array which is generated at runtime. Hence the number of name/data pairs varies.
我有跟随在运行时生成的json数组。因此,名称/数据对的数量变化。
`var sales = { "SalesData" : [
{ "name" : "AllProducts|Canada", "data" :[44936.0,50752.0] },
{ "name" : "AllProducts|Mexico", "data" : [200679.0,226838.0] },
{ "name" : "AllProducts|USA", "data" : [288993.0,289126.0] }
]} `
I want to pass this data to series in highcharts.
我想将这些数据传递给highcharts中的系列。
This is how I am doing it currently.
这就是我目前的做法。
series: [
{name:sales.SalesData[0].name,data:sales.SalesData[0].data},
{name:sales.SalesData[1].name,data:sales.SalesData[1].data},
{name:sales.SalesData[2].name,data:sales.SalesData[2].data}
]
But if the number of elements in array are changed then this won't work. How do I solve this problem ? Demo code will help me.
但是如果数组中的元素数量发生了变化,那么这将不起作用。我该如何解决这个问题?演示代码将帮助我。
I have refereed following questions but I was not able to solve the problem.
我已经审问了以下问题,但我无法解决问题。
Dynamically adding to Highcharts
动态添加到Highcharts
Highcharts series data array
Highcharts系列数据阵列
2 个解决方案