0

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

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

2 Comments

Can you mark this as the correct answer? Thanks in advance!
Yes, all set. BTW, I posted another question regarding refresh. No sure if you can help there. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.