<canvas canvas-id="canvasMix" id="canvasMix" class="charts" :width="cWidth*pixelRatio" :height="cHeight*pixelRatio"
:style="{'width':cWidth+'px','height':cHeight+'px'}" disable-scroll=true @touchstart="touchMix"></canvas>
import uCharts from '@/components/u-charts/u-charts.js';
var _self = this;
//获取数据
GetData() {
uni.request({
url: api地址,
data: {},
method: 'GET',
success: (res) => {
//双Y轴
this.mixChartData.categories = res.data.monthList;
this.mixChartData.series.push(res.data.leftYList);
this.mixChartData.series.push(res.data.rightYList);
this.mixChartData.series[1].index = 1;
_self.showMix("canvasMix", this.mixChartData);
},
fail: (data, code) => {
console.log('fail' + JSON.stringify(data));
},
complete: () => {
}
})
},
showMix(canvasId, chartData) {
**//格式化图表上数据显示**
for (let i = 0; i < chartData.series.length; i++) {
if (chartData.series[i].index === 1) {
chartData.series[i].format = (val) => {
return val + '%'
};
}
}
canvaMix = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'mix',
fontSize: 11,
padding: [5, 5, 0, 5],
colors: ['#1890ff', '#2fc25b', '#facc14', '#f04864', '#8543e0', '#90ed7d'], //自定义颜色
legend: {
show: true,
position: 'bottom',
float: 'center',
padding: 5,
lineHeight: 11,
margin: 6,
},
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
categories: chartData.categories,
series: chartData.series,
animation: true,
enableScroll: true, //开启图表拖拽功能
xAxis: {
disableGrid: false,
type: 'grid',
gridType: 'dash',
itemCount: 4,
scrollShow: true,
scrollAlign: 'left',
},
yAxis: {
data: [{
calibration: true,
position: 'left',
title: '完成总数',
min: 0,
max: _self.monthMaxSum,
titleFontSize: 12,
format: (val) => {
return val.toFixed(0)
}
}, {
calibration: true,
position: 'right',
min: 0,
max: 100,
title: '及时率',
titleFontSize: 12,
format: (val) => {
return val.toFixed(2) + '%'
}
}],
showTitle: true,
gridType: 'dash',
dashLength: 4,
splitNumber: 5 //Y轴网格数量
},
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
dataLabel: true,
dataPointShape: true,
extra: {
column: {
width: 20 * _self.pixelRatio
},
tooltip: {
showBox: false, //是否显示半透明黑色的提示区域
bgColor: '#000000',
bgOpacity: 0.7,
gridType: 'dash',
dashLength: 8,
gridColor: '#1890ff',
fontColor: '#FFFFFF',
horizentalLine: true,
xAxisLabel: true,
yAxisLabel: true,
labelBgColor: '#DFE8FF',
labelBgOpacity: 0.95,
labelAlign: 'left',
labelFontColor: '#666666'
}
},
});
},
记录uniapp使用uCharts格式化图表上数据显示(显示%)
最新推荐文章于 2024-05-03 11:08:18 发布