Reputation: 53
I have the following json that's returned from a C# web api as a name value pair.
{
{
"Grouping": "Label0",
"Count": 71
},
{
"Grouping": "Label1",
"Count": 44
},
{
"Grouping": "Label2",
"Count": 18
},
{
"Grouping": "Label3",
"Count": 34
}
}
I need to cast this data set to support a highchart pie chart. The pie chart requires data in the form of
{
name: <>,
y: <>,
drilldown: <>
}
How can I cast the retrieved Name value pair into the expected json for highchart? Thanks
Upvotes: 0
Views: 338
Reputation: 884
You can always parse the received data to match the date format in highcharts: https://www.highcharts.com/docs/working-with-data/custom-preprocessing
var data = [{
"yearmonth": '2019 - 01',
"sales": 30
}, {
"yearmonth": '2019 - 02',
"sales": 66
}, {
"yearmonth": '2019 - 03',
"sales": 52
}],
parsedData = [];
data.forEach(element => {
parsedData.push({
name: element.yearmonth,
y: element.sales
});
});
A simple example: https://jsfiddle.net/BlackLabel/fsvrmd3u/
Upvotes: 1