前言
<template>
<canvas canvas-id="canvasId" id="canvasId" class="w-500 h-500"/>
</template>
<script>
import echarts from './charts.js';
export default {
data() {
return {
chartsWidth: 500,
chartsHeight: 500,
}
}
},
onReady() {
this.chartsWidth = uni.upx2px(500);
this.chartsHeight = uni.upx2px(500);
this.getData();
},
</script>
柱状图
getData() {
let dataInfo = {
categories:[2020,2021,2022,2023,2024],
series:[
{
name:'名称',
data:[100,200,300]
}
]
}
this.drawCharts('canvasId', dataInfo);
},
drawCharts(id, dataInfo) {
const ctx = uni.createCanvasContext(id, this);
new echarts({
type: "column",
context: ctx,
width: this.chartsWidth,
height: this.chartsHeight,
categories: dataInfo.categories,
series: dataInfo.series,
dataLabel: false,
animation: true,
background: "#FFFFFF",
color: ["#404EF3", "#EE6666", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
padding: [15, 15, 0, 5],
enableScroll: false,
legend: {
show:true,
fontColor: "#FFFFFF",
position: "top",
float: "right",
fontSize: 12,
},
xAxis: {
disabled: false,
disableGrid: true,
axisLineColor: "#0746a3",
calibration: false,
fontColor: "#FFFFFF",
fontSize: 13,
rotateLabel: false,
rotateAngle: 45,
},
yAxis: {
disabled: false,
disableGrid: false,
gridType: "dash",
dashLength: 8,
gridColor: "#0f5681",
showTitle: true,
data: [
{
axisLineColor: "#0746a3",
calibration: false,
fontColor: "#FFFFFF",
fontSize: 13,
textAlign: "right",
title: "单位(人)",
titleFontSize: 13,
titleOffsetY: -5,
titleOffsetX: 0,
titleFontColor: "#FFFFFF",
unit: "",
min: 0,
},
],
},
extra: {
column: {
type: "group",
width: 30,
activeBgColor: "#FFFFFF",
activeBgOpacity: 1,
linearType: "custom",
seriesGap: 5,
categoryGap: 2,
linearOpacity: 0.5,
barBorderCircle: true,
customColor: [
"#6AE7FD",
"#404EF3"
]
}
}
});
},