The bar graph is generated from the JSON result set, and the first column is fixed to the description, followed by the column Value field.
<! DOCTYPE html>//Path Configurationrequire.config ({paths: {echarts:' Http://echarts.baidu.com/build/dist ' } }); /*var json_data = [{"title": "Shirt", "Value": 5, "value1": 15},{"title": "Cardigan", "value": "value1": 15},{"title": "Chiffon Shirt", " Value ":", "value1": [+], {"title": "Trousers", "value": "Value1": "15},{", "title": "High Heels", "value": "value1": 25},{"title": " Socks "," value ":" Value1 ": 25}]; */ varJson_data = [{"title": "Shirt", "Value": 5, "value1": "value2": 15},{"title": "Cardigan", "value": "Value1": "value2": 15} ,{"title": "Chiffon Shirt", "value": 15, "value1": "value2": 15},{"title": "Trousers", "value": $, "value1": +, "value2": +/----+-----------} ,{"title": "High Heels", "value": 15, "value1": "value2": 15},{"title": "Socks", "value": All, "value1": +, "value2":}]; varCol_title = "";//column name of title, fixed to first column varCol_data = [];//starting from the second column, the Value field, ["Value", "value1"]; varCol_data_name =[];//starting from the second column, for the Value field, ["Sales", "value Two"]; varChart_title =NewArray ();//title Bellow Group varChart_data =NewArray ();//array of Values //column header, column field name value varCol = 0; for(varKeyinchJson_data[0]){ if(col==0) Col_title=key; Else{Col_data.push (key); Col_data_name.push (key); } Col++; } //assigning values to a value field for(varI =0;i<col_data.length;i++) {Chart_data[i]= { "Name": Col_data_name[i],' type ': ' Bar ', "Data": []//[5 , +, +, ten, Ten,] }; } //fill in the title and data of each value for(vari=0;i<json_data.length;i++) {Chart_title.push (json_data[i]["Title"]); for(varJ =0;j<col_data.length;j++){ varCol_name =Col_data[j]; Chart_data[j].data.push (Json_data[i][col_name]); //Chart_data[1].data.push (json_data[i]["value1"]); }; }; //Userequire ([' Echarts ', ' Echarts/chart/bar '//load bar module with bar chart, load on Demand ], function(EC) {//Initialize the Echarts chart based on the prepared Dom varMyChart = Ec.init (document.getElementById (' main '))); varoption ={tooltip: {show:true}, Legend: {data:col_data_name}, Xaxis: [{type:' Category ', Data:chart_title//["Shirts", "sweaters", "chiffon shirts", "trousers", "high Heels", "socks"]}], YAxis: [{ Type:' Value '}], series:chart_data}; //loading data for Echarts objectsmychart.setoption (option); } ); </script></body>
Echart-Generate bar graph based on JSON return value