onLoad() {
this.echartsComponnet = this.selectComponent('#mychart-dom-pie');
this.init_echarts()
},
init_echarts() {
let t = this
this.echartsComponnet.init((canvas, width, height, dpr) => {
// 初始化图表
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr // new
});
var option = {
series: [{
name: 'Access From',
type: 'pie',
emphasis: {
label: {
show: true,
color: "#D6000F",
formatter: "{d}%",
fontSize: '16',
},
},
color: [
'#FF5300',
'#34AA27',
],
radius: ['60%', '90%'],
// radius: ['10%', '90%'],
itemStyle: {
borderRadius: 5,
// borderColor: '#fff',
},
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
},
labelLine: {
show: false
},
data: [{
name: "张三",
value: 40
}, {
name: "李四",
value: 60
}]
}]
};
chart.setOption(option);
setTimeout(() => {
t.echartsComponnet.canvasToTempFilePath({
// x: 50,
// y: 50,
// // width:100,
// // height:100,
// destWidth:10,
// destHeight:50,
// canvasId: 'myShareCanvas',
success: function (res) {
t.setData({
chartTempImg: res.tempFilePath // 保存生成图片路径
});
},
fail: function () {
console.log("echarts生成失败")
}
})
},1000);
chart.on('mousedown', function (params) {
chart.dispatchAction({
type: 'downplay',
seriesIndex: 0
})
chart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: params.dataIndex
});
t.setData({
index: params.dataIndex
})
})
return chart;
})
}
将echarts转化为图片
最新推荐文章于 2024-03-23 03:46:22 发布