Echart receives json data

problem description

echartK 
jsonKdatajson 

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Aug.09,2021

use Object.values () to convert the values in the JSON string into an array, but the values of JSON should be arranged in alphabetical order, otherwise the converted values will be confused


.
//arr
var arrf=[];
//
var arrs1=[];
var arrs2=[];
//json
var json = {
    "data": {
        "data": [{
            "id": 1,
            "name": "1",
        },{
            "id": 2,
            "name": "2",
        },{
            "id": 3,
            "name": "3",
        },{
            "id": 4,
            "name": "4",
        },{
            "id": 5,
            "name": "5",
        },{
            "id": 6,
            "name": "6",
        },{
            "id": 7,
            "name": "7",
        },{
            "id": 8,
            "name": "8",
        },{
            "id": 9,
            "name": "9",
        }]
    },
}
for(var i=0;i<json.data.data.length;iPP){
    arrs1.push(json.data.data[i].id);
    arrs2.push(json.data.data[i].name);
    arrf[i]=[arrs1[i],arrs2[i]]
}
console.log(arrf);

the results obtained are
[[1, 'quality control platform 1'],
[2, 'quality control platform 2'],
[3, 'quality control platform 3'],
[4, 'quality control platform 4'],
[5, 'quality control platform 5'],
[6, 'quality control platform 6'],
[7, 'quality control platform 7'],
[8, 'QC platform 8'],
[9, QC platform 9']


data structure conversion is an unavoidable problem. There is no way to require that the data obtained is the data needed by the framework.
moreover, in the chart, order is very important information and can not be discarded. An ordered data structure (array) is much more suitable than the unordered structure of json (kv key-value pairs.

http://echarts.baidu.com/tuto.
echarts can use dataset instead of data, but structural transformation is still inevitable, so, yes, the structure of the data must be transformed.

Menu