简体   繁体   中英

Create Json X,Y structure

I am trying to create the below structure:

"chartData": [
                    {
                        label: "Your group",
                        data: [
                            [-2, 10],
                            [2, 20],
                            [-1, 11],
                            [-1, -12],
                            [-1, 5]
                        ],
                        info: [
                            {
                                id: "a1"
                            },
                            {
                                id: "b1"
                            },
                            {
                                id: "c1"
                            },
                            {
                                id: "d1"
                            },
                            {
                                id: "e1"
                            }
                        ]
                    },

everything is fine other than the data section. If I create a class to represent each data point, with for example a property for X and a property for Y then the JSON created will look something like this:

 "chartData": [
                        {
                            label: "Your group",
                            data: [
                                {X=-2, Y=10},
                                {X=-5, Y=17},
                                {X=-1, Y=13},
                                {X=-8, Y=8},
                                {X=-5, Y=13}
                            ],
                            info: [
                                {
                                    id: "a1"
                                },
                                {
                                    id: "b1"
                                },
                                {
                                    id: "c1"
                                },
                                {
                                    id: "d1"
                                },
                                {
                                    id: "e1"
                                }

Defining the data type to be a double[,] also doesn't create the same format. I need to stick to this format as it at the request of an external vendor that the data looks like this. Any ideas?

Your coordinate pairs need to be an array of int or double .

class ChartData {
    string label;
    int[][] data;
    Info[] info;
}

data should be initialized like this:

var cd = new ChartData();
cd.data = new int[100][];

And, each point should be something like:

cd.data[0] = new[] { 1, 1 };
cd.data[1] = new[] { -10, 50};
//etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM