I have some JSON Data object and its needs to convert into Highchyour text
arts Series data, I tried lot with my minimal knowledge in JS, but I can’t:
Json Object:
{"Matrix":[{"mdate":2002-02-09,"mvalue":33.0,"mt":23,"mb":99},
{"mdate":2002-02-09,"mvalue":34.0,"mt":23,"mb":99},
{"mdate":2002-03-09,"mvalue":39.0,"mt":23,"mb":99},
{"mdate":2002-04-09,"mvalue":340.0,"mt":23,"mb":99},
{"mdate":2002-05-09,"mvalue":348.0,"mt":23,"mb":99}
]
}
The above data needs to be converted to be like below:
and I want to display the mdate on x axis categories and the Matrix as title.
series: [
{
name: 'm-1',
data: [33.0,23,99],
}, {
name: 'm-2',
data: [34.0,23,99],
},
]
Please help me out to fix this , Thanks in Advance.
2
Answers
To convert your JSON data object into Highcharts Angular series data, you can iterate over the "Matrix" array in your JSON and transform each item into the desired format. Here’s an example of how you can achieve this:
This code will iterate over each item in the "Matrix" array and create an object for each item in the desired format. The name property is set to
m-
followed by the mvalue from each item. The data property is an array containingmvalue
,mt
, andmb
from each item. The converted series data is then pushed into theseriesData
array.Make sure to adjust the code according to your Angular component and Highcharts configuration. You can assign the
seriesData
to your Highcharts configuration object or use it as needed in your application.The easiest way I could think of is the JavaScript array map() function. This will allow you to transform the data.
Sample HighChart: