<template> <div> <div ref="barChart" style="width: 800px; height: 600px;"></div> </div> </template> <script> import * as echarts from 'echarts'; import iconA from '@/assets/mhImg/iconTest.png'; // import iconB from '@/assets/icons/icon-b.png'; // import iconC from '@/assets/icons/icon-c.png'; export default { data() { return { types: ['A', 'B', 'C', 'D', 'E', 'F'], values: [20, 30, 15, 40, 25, 35], iconA: iconA, // icons: [iconA, iconB, iconC] // 图片路径数组 }; }, mounted() { this.initChart(); }, methods: { initChart() { const chartDom = this.$refs.barChart; const myChart = echarts.init(chartDom); const option = { // 自定义图例配置 legend: { data: this.types.map((type, index) => ({ name: type, icon: type=='A' ? `image://${iconA}` : '' })) }, // // 配置图例,循环使用 assets 图片 // legend: { // data: this.types.map((type, index) => ({ // name: type, // icon: `image://${this.icons[index]}` // 关键:使用 image:// 前缀 // })) // }, xAxis: { type: 'category', data: this.types }, yAxis: { type: 'value' }, series: this.types.map((type, index) => ({ name: type, type: 'bar', data: [this.values[index]] })) }; myChart.setOption(option); } } }; </script>
来源链接:https://www.cnblogs.com/fkcqwq/p/18872129
© 版权声明
本站所有资源来自于网络,仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您(转载者)自己承担!
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
THE END
暂无评论内容