echarts自定义图片显示比例

 "echarts": "^5.2.0", 

<template>
	<div :class="className" :style="{height:height,width:width}" id="myChartMale" />
</template>

<script>
	import * as echarts from 'echarts';
	import resize from '@/utils/resize.js'
	export default {
		mixins: [resize],
		props: {
			className: {
				type: String,
				default: 'chart'
			},
			width: {
				type: String,
				default: '15vw'
			},
			height: {
				type: String,
				default: '5vh'
			},
			chartData: {
				type: Array,
				required: true
			}
		},
		data() {
			return {
				timer: 0,
			}
		},
		watch: {
			chartData: {
				deep: true,
				handler(val) {
					this.setOption(val)
				}
			}
		},
		mounted() {
			this.initChart();
		},
		beforeDestroy() {},
		methods: {
			initChart() {
				var myChart = echarts.init(document.getElementById('myChartMale'));
				const maleBlue ='image://'+ require('@/assets/sjbig/male_blue.png');//自定义图片
				const maleGray ='image://'+ require('@/assets/sjbig/male_white.png');
				var maxData = 100;
				var option = {
					tooltip: {},
					  xAxis: {
					    show:false,
					    max: maxData,
					    splitLine: { show: false },
					    offset: 10,
					    axisLine: {
					      lineStyle: {
					        color: '#999'
					      }
					    },
					    axisLabel: {
					      margin: 10
					    }
					  },
					  yAxis: {
					    data: [''],
					    inverse: true,
					    axisTick: { show: false },
					    axisLine: { show: false },
					   
					  },
					  grid: {
					    // top: 'center',
						
					    left: 0,
					    right: 0
					  },
					  series: [
					    {
					      // current data
					      type: 'pictorialBar',
					      symbol: maleBlue,
					      symbolRepeat: 'fixed',
					      symbolMargin: '0',
					      symbolClip: true,
					      symbolSize: 35,
					      data: [70],
					      z: 10
					    },
					    {
					      // full data
					      type: 'pictorialBar',
					      // itemStyle: {
					      //   opacity: 0.1
					      // },
					      label: {
					        show: false,
					      },
					      animationDuration: 0,
					      symbolRepeat: 'fixed',
					      symbolMargin: '0',
					      symbol: maleGray,
					      symbolSize: 35,
					      symbolBoundingData: maxData,
					      data: [30],
					      z: 5
					    }
					  ]
				};

				myChart.setOption(option);
				window.addEventListener('resize', function() {
					myChart.resize()
				})
				// window.addEventListener('resize', myChart.resize);


			},


		}
	}
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值