js的多种数值分类相加,数据先后没有顺序,不确定同类数据多少
下面是js源码片段。看的是思想。
<script type="text/javascript"> deg_countMyChart = function(deptcode){ //定义图表展示数组数据 var areatypeMyChart = [];//类型 var mianjiaraeMyChart = [];//面积 $.ajax({ type : "GET", url : rootPath + "/areatype/getAreatypeStatisList.jspx", dataType : "json", success : function(result) { if(result.success){ var Area=0; var Area1=0; var AreaName1=""; var Area2=0; var AreaName2=""; var Area3=0; var AreaName3=""; var Area4=0; var AreaName4=""; var j=0; var size = result.obj.length; for(var i = 0; i<size; i++){ var co= result.obj[i].coordinates; var coordinates = stringToPointArr_arcgis(co); var myPolygon = new esri.geometry.Polygon( new esri.SpatialReference({wkid : 4024})); myPolygon.addRing(coordinates); if(myPolygon.type == "polygon") { var geo = esri.geometry.webMercatorToGeographic(myPolygon); Area = esri.geometry.geodesicAreas([geo], esri.Units.SQUARE_METERS); if(result.obj[i].areatype=='0030101'){//重点监测区 var dd=(Area*0.0001).toFixed(2); Area1= parseInt(Area1)+parseInt(dd); AreaName1=result.obj[i].areatypename; } if(result.obj[i].areatype=='0030102'){//重点监测区 var dd=(Area*0.0001).toFixed(2); Area2= parseInt(Area2)+parseInt(dd); AreaName2=result.obj[i].areatypename; } if(result.obj[i].areatype=='0030103'){//重点监测区 var dd=(Area*0.0001).toFixed(2); Area3= parseInt(Area3)+parseInt(dd); AreaName3=result.obj[i].areatypename; } if(result.obj[i].areatype=='0030104'){//重点监测区 var dd=(Area*0.0001).toFixed(2); Area4= parseInt(Area4)+parseInt(dd); AreaName4=result.obj[i].areatypename; } } } mianjiaraeMyChart.push(Area1); areatypeMyChart.push(AreaName1); mianjiaraeMyChart.push(Area2); areatypeMyChart.push(AreaName2); mianjiaraeMyChart.push(Area3); areatypeMyChart.push(AreaName3); mianjiaraeMyChart.push(Area4); areatypeMyChart.push(AreaName4); countMyChart(areatypeMyChart,mianjiaraeMyChart); } else { parent.$.messager.alert('警告', result.msg, 'warning'); return false; } } }); } countMyChart = function(areatype,areatypeMyChart){ $("#prairieDeg_count_chart").show(); // 基于准备好的dom,初始化echarts图表 var prairieDegMyChart = echarts.init(document.getElementById('prairieDeg_count_chart')); //内置主题('macarons', 'infographic') var option = { tooltip: { show: true }, legend: { data:['总公顷']//','发生区','预报检测区','重点监测区 }, toolbox: { show : true, feature : { dataView : {show: true, readOnly: false}, magicType : {show: true, type: ['line', 'bar']}, restore : {show: true}, saveAsImage : {show: true,name:'统计分析数据—生产力预警'} } }, calculable : true, xAxis : [ { "name":"区域类型", type : 'category', data :areatype, axisLabel:{ interval:0, rotate:13, //倾斜度 -90 至 90 默认为0 margin:10, textStyle:{ fontWeight:"bolder", color:"#000000" } } } ], yAxis : [ { "name":"面积/公顷", type : 'value' } ], series : [ { "barWidth" : "40", "name":"总公顷", "type":"bar", "data":areatypeMyChart,//-- itemStyle: { normal: { label: { show: true, position: 'top', formatter: '{c}' } } } } ] }; // 为echarts对象加载数据 prairieDegMyChart.setOption(option); } </script>
},
toolbox: {
show : true,
feature : {
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar']},
restore : {show: true},
saveAsImage : {show: true,name:'统计分析数据—生产力预警'}
}
},
calculable : true,
xAxis : [
{
"name":"区域类型",
type : 'category',
data :areatype,
axisLabel:{
interval:0,
rotate:13, //倾斜度 -90 至 90 默认为0
margin:10,
textStyle:{
fontWeight:"bolder",
color:"#000000"
}
}
}
],
yAxis : [
{
"name":"面积/公顷",
type : 'value'
}
],
series : [
{
"barWidth" : "40",
"name":"总公顷",
"type":"bar",
"data":areatypeMyChart,//--
itemStyle: {
normal: {
label: {
show: true,
position: 'top',
formatter: '{c}'
}
}
}
}
]
};
// 为echarts对象加载数据
prairieDegMyChart.setOption(option);
}
</script>