wylyl22 3 years ago
parent 1e73cc84db
commit 94977e91e9

@ -48,10 +48,9 @@ Component({
let pd=res.sex.length==1
// res.forEach(ele => {
// })
if(!pd){
for(let i=0;i<res.region.length;i++){
regionSum+=res.region[i].value
console.log(regionSum)
// console.log(regionSum)
}
for(let i=0;i<res.region.length/2;i++){
rName1.push(res.region[i].key ||'')
@ -61,28 +60,26 @@ Component({
rName2.push(res.region[i].key)
rValue2.push(res.region[i].value)
}
}
for(let i=0;i<3;i++){
if(!pd){
sexSum+=sex[i].value
attestationSum+=attestation[i].value
}
attestationSum+=attestation[i].value
}
for(let i=0;i<3;i++){
if(!pd){
sexAccounted.push(((sex[i].value/sexSum)*100).toFixed(2))
attestationAccounted.push(((attestation[i].value/attestationSum)*100).toFixed(2))
sexList.push({name:sex[i].key,value:sex[i].value,color:color[i],accounted:sexAccounted[i]})
attestationList.push({name:attestation[i].key,value:attestation[i].value,color:color[i],accounted:attestationAccounted[i]})
}
sexAccounted.push(((sex[i].value/sexSum)*100).toFixed(2))
attestationAccounted.push(((attestation[i].value/attestationSum)*100).toFixed(2))
sexList.push({name:sex[i].key,value:sex[i].value,color:color[i],accounted:sexAccounted[i]})
attestationList.push({name:attestation[i].key,value:attestation[i].value,color:color[i],accounted:attestationAccounted[i]})
}
console.log(rName1,rValue1,regionSum)
console.log(rName2,rValue2,regionSum)
this.setData({
sexList:pd?[]:sexList,
attestationList:pd?[]:attestationList,
sexOption:pd?pieOption([],'#fff'):pieOption(color,sex),
attestationOption:pd?pieOption():pieOption(color,attestation),
regionOption1:pd?pictographicOption():pictographicOption(rName1,rValue1,regionSum),
regionOption2:pd?pictographicOption():pictographicOption(rName2,rValue2,regionSum),
sexList:sexList,
attestationList:attestationList,
sexOption:pieOption(color,sex),
attestationOption:pieOption(color,attestation),
regionOption1:pictographicOption(rName1,rValue1,regionSum),
regionOption2:pictographicOption(rName2,rValue2,regionSum),
})
})
setTimeout(() =>{

@ -56,10 +56,10 @@
<view class="text">地区</view>
<view class="echars">
<view class="echars_view">
<c-echars showChart="{{showChart}}" canvasId="region-canvas" chartId="regionbar" chartOption="{{regionOption1}}" height="100%"></c-echars>
<c-echars showChart="{{showChart}}" canvasId="region-canvas1" chartId="regionbar1" chartOption="{{regionOption1}}" height="100%"></c-echars>
</view>
<view class="echars_view">
<c-echars showChart="{{showChart}}" canvasId="region-canvas" chartId="regionbar" chartOption="{{regionOption2}}" height="100%"></c-echars>
<c-echars showChart="{{showChart}}" canvasId="region-canvas2" chartId="regionbar2" chartOption="{{regionOption2}}" height="100%"></c-echars>
</view>
</view>

@ -9,7 +9,7 @@ export default function pictographicOption(dRegion = [], dValue = [], dSum = 0)
textStyle: {
color: "#fff", //设置文字颜色
fontSize: 9
},
},},
xAxis: {
show:false,
type:'value'
@ -43,18 +43,18 @@ export default function pictographicOption(dRegion = [], dValue = [], dSum = 0)
},
// current data
type: 'bar',
barWidth:10,
barWidth:8,
data:dValue,
label: {
show: true,
formatter: function (params) {
return ((params.value / 100) * 100).toFixed(1) + ' %';
return ((params.value / dSum) * 100).toFixed(2) + ' %';
},
// position: 'right',
// offset: [20, 0],
color: '#333333',
fontSize: 12,
position:[60,-4]
position:[50,-5]
},
showBackground: true,
backgroundStyle: {
@ -67,4 +67,3 @@ export default function pictographicOption(dRegion = [], dValue = [], dSum = 0)
]
}
}
}
Loading…
Cancel
Save