web-africa-h5/pages/market/performance/monthlyPerformanceComparison/FirstPurchaseDistribution.vue

281 lines
7.4 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="content">
<view class="charts-box d-c-c">
<canvas canvas-id="NshYKDfHxforVwikhuwWRIJdiwKUdCfN" id="NshYKDfHxforVwikhuwWRIJdiwKUdCfN" class="charts" @touchend="tap" />
</view>
<view class="tabulation-box">
<view class="tabulation-top d-c-c">
<view class="flex-1 tc fb f28"></view>
<view class="flex-1 tc">
<text class="fb f28">{{$t('ENU_TOTAL_V_1')}}</text>
<text class="f22 gray9">({{$t('S_C_58')}})</text>
</view>
<view class="flex-1 tc"><text class="fb f28">{{$t('N_I_106')}}</text></view>
</view>
<template v-if="chartsDataColumn.series && chartsDataColumn.series[0]">
<view class="d-b-c tabulation-item" v-for="(item, index) in chartsDataColumn.series[0].data" :key="index">
<view class="flex-1 f28 gray6 tc">{{ item.name }}</view>
<view class="flex-1 f28 gray6 tc">{{ item.value }}</view>
<view class="flex-1 f28 gray6 tc">{{ item.value1 }}</view>
</view>
</template>
</view>
</view>
</template>
<script>
import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';
var uChartsInstance = {};
export default {
data() {
return {
cWidth: 661,
cHeight: 638,
chartsDataColumn: {}
};
},
onLoad() {
//这里的 750 对应 css .charts 的 width
this.cWidth = uni.upx2px(661);
//这里的 500 对应 css .charts 的 height
this.cHeight = uni.upx2px(638);
this.getServerData();
},
methods: {
tap(e) {
let self = this;
uChartsInstance[e.target.id].touchLegend(e);
// uChartsInstance[e.target.id].showToolTip(e);
var index = uChartsInstance[e.target.id].getCurrentDataIndex(e);
console.log(index);
let data = uChartsInstance[e.target.id].opts.series[index];
if (index < 0) {
return;
}
uChartsInstance[e.target.id].showToolTip(e, {
textList: [
{ text: data.name + ':' + data.value1 + data.className, color: '#fff' },
{ text: self.$t('ENU_TOTAL_V_1') + ':' + data.value + data.className1, color: '#fff' }
]
});
},
getServerData() {
let self = this;
self.loading = true;
self._get('report/api/achieve/query-first-performance-pic', {}, res => {
let list = res.data;
let obj = {
series: [
{
data: [
{
value1: res.data.leftPeopleNumber * 1,
value: res.data.leftAchieve * 1,
name: self.$t('S_C_18'),
className: self.$t('S_C_67'),
className1: self.$t('S_C_58'),
labelText:
self.$t('S_C_18') +
res.data.leftPeopleNumber * 1 +
self.$t('S_C_67') +
' ' +
self.$t('ENU_TOTAL_V_1') +
res.data.leftAchieve * 1 +
self.$t('S_C_58')
},
{
value1: res.data.rightPeopleNumber * 1,
value: res.data.rightAchieve * 1,
name: self.$t('S_C_19'),
className: self.$t('S_C_67'),
className1: self.$t('S_C_58'),
labelText:
self.$t('S_C_19') +
res.data.rightPeopleNumber * 1 +
self.$t('S_C_67') +
' ' +
self.$t('ENU_TOTAL_V_1') +
res.data.rightAchieve * 1 +
self.$t('S_C_58')
}
],
format: 'pieDemo'
}
]
};
console.log(obj);
self.chartsDataPie1 = obj;
self.chartsDataColumn = JSON.parse(JSON.stringify(obj));
self.drawCharts('NshYKDfHxforVwikhuwWRIJdiwKUdCfN', self.chartsDataColumn);
});
},
drawCharts(id, data) {
const ctx = uni.createCanvasContext(id, this);
uChartsInstance[id] = new uCharts({
type: 'pie',
context: ctx,
width: this.cWidth,
height: this.cHeight,
series: data.series,
animation: true,
timing: 'easeOut',
duration: 1000,
rotate: false,
rotateLock: false,
background: '#FFFFFF',
color: ['#ff5a5a', '#ffae36', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
padding: [5, 5, 5, 5],
fontSize: 9,
fontColor: '#666666',
dataLabel: false,
dataPointShape: true,
dataPointShapeType: 'solid',
touchMoveLimit: 60,
enableScroll: false,
enableMarkLine: false,
legend: {
show: true,
position: 'bottom',
float: 'center',
padding: 5,
margin: 5,
backgroundColor: 'rgba(0,0,0,0)',
borderColor: 'rgba(0,0,0,0)',
borderWidth: 0,
fontSize: 9,
fontColor: '#666666',
lineHeight: 11,
hiddenColor: '#CECECE',
itemGap: 10
},
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: 0,
labelWidth: 15,
border: true,
borderWidth: 3,
borderColor: '#FFFFFF',
customRadius: 0,
linearType: 'none'
},
tooltip: {
showBox: true,
showArrow: true,
showCategory: false,
borderWidth: 0,
borderRadius: 0,
borderColor: '#000000',
borderOpacity: 0.7,
bgColor: '#000000',
bgOpacity: 0.7,
gridType: 'solid',
dashLength: 4,
gridColor: '#CCCCCC',
boxPadding: 3,
fontSize: 13,
lineHeight: 20,
fontColor: '#FFFFFF',
legendShow: true,
legendShape: 'auto',
splitLine: true,
horizentalLine: false,
xAxisLabel: false,
yAxisLabel: false,
labelBgColor: '#FFFFFF',
labelBgOpacity: 0.7,
labelFontColor: '#666666'
}
}
});
},
getServerData1() {
setTimeout(() => {
//因部分数据格式一样,这里不同图表引用同一数据源的话,需要深拷贝一下构造不同的对象
//开发者需要自行处理服务器返回的数据应与标准数据格式一致注意series的data数值应为数字格式
this.chartsDataLine1 = JSON.parse(JSON.stringify(demodata.Line));
//数据点格式化示例
//使用format属性指定config-ucharts.js里事先定义好的formatter的key值组件会自动匹配与其对应的function
let columnFormatDemo = JSON.parse(JSON.stringify(demodata.Column));
for (var i = 0; i < columnFormatDemo.series.length; i++) {
columnFormatDemo.series[i].format = 'seriesDemo1';
}
this.chartsDataColumn2 = columnFormatDemo;
//饼图格式化示例
//使用format属性指定config-ucharts.js里事先定义好的formatter的key值组件会自动匹配与其对应的function
let pieFormatDemo = JSON.parse(JSON.stringify(demodata.PieA));
for (var i = 0; i < pieFormatDemo.series.length; i++) {
pieFormatDemo.series[i].format = 'pieDemo';
}
this.chartsDataPie1 = pieFormatDemo;
console.log(pieFormatDemo);
}, 1500);
}
}
};
</script>
<style>
page {
/* background-color: #fff; */
}
.content {
padding: 26rpx 22rpx 26rpx 23rpx;
}
.content-box {
padding: 30rpx 0;
min-height: 100vh;
}
.picker-small {
width: 232rpx;
height: 72rpx;
border: 1rpx solid #eeeeee;
border-radius: 15rpx;
font-size: 28rpx;
padding: 0 28rpx 0 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
.charts-box {
padding: 22rpx 26rpx 23rpx 28rpx;
width: 706rpx;
height: 692rpx;
box-sizing: border-box;
background: #ffffff;
border-radius: 20rpx;
margin: 0 auto;
margin-bottom: 30rpx;
}
.charts {
width: 661rpx;
height: 638rpx;
}
.tabulation-box {
width: 704rpx;
padding: 26rpx 26rpx 35rpx 26rpx;
box-sizing: border-box;
background: #ffffff;
border-radius: 20rpx;
margin: 0 auto;
}
.tabulation-top {
padding: 20rpx 0;
border-bottom: 1prx solid #eee;
}
.tabulation-item {
height: 68rpx;
}
.tabulation-item:nth-child(2n) {
background: #f8f8f8;
}
</style>