quasar
quasar

Reputation: 474

Converting a complex json format to C# class for Highchart Organization Chart

I'm trying to achieve Highcharts JSON data format for Organization chart (organogram) which indeed an inverted Sankey chart as well for my asp.net MVC project. The series property of the chart mainly holds the data, nodes and levels information. I'm not getting such complex JSON format examples on StackOverflow or elsewhere. The JSON structure excerpt as following -

{
//Some other Highcharts properties
series: [
 data: [
      ['Board', 'CEO'],
      ['CEO', 'CTO'],
      ['CEO', 'CMO'],
      ['CEO', 'HR'],
      ['CTO', 'Product'],
      ['CTO', 'Web'],
      ['CMO', 'Market']
 ],
 levels:[
      {
      level: 0,
      color: 'silver',
      dataLabels: {
        color: 'black'
      },
      height: 25
    }, 
    {
      level: 1,
      color: 'silver',
      dataLabels: {
        color: 'black'
      },
      height: 25
    }
//..more
 ],
 nodes:[
    {
      id: 'CEO',
      title: 'CEO',
      name: 'Grethe Hjetland',
      image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg'
    }, 
    {
      id: 'HR',
      title: 'HR/CFO',
      name: 'Anne Jorunn Fjærestad',
      color: '#007ad0',
      image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg',
      column: 3,
      offset: '80%'
    }, 
    {
      id: 'CTO',
      title: 'CTO',
      name: 'Christer Vasseng',
      column: 4,
      image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg',
      layout: 'hanging'
    }
//..more
 ]
]
//Rest of the Highcharts properties
}

You can check for Highcharts docs- https://www.highcharts.com/docs/chart-and-series-types/organization-chart

Mainly I've problems with data array property of series. Will jagged array work in this scenario? The levels and nodes property, I guess, will be an array of the object list. So finally how can I achieve this goal with implementation in the razor view page?

Upvotes: 1

Views: 282

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26362

Why use a jagged array?

A jagged array is an array whose elements are arrays.

This is just a list of strings for each of the data items, which would cover most of your problems.

The json object is not complex. You will just have to create a C# class for each of the different json data types in your structure.

Something like the following.

public class Highchart {
    public List<Series> series;
}

public class Series {
    public List<string> data;
    public List<Level> levels;
    // etc for the rest
}

public class Level {
    // The level properties here.
}

// The same for all objects

Upvotes: 1

Related Questions