echarts清除图标信息、echarts添加点击事件、echarts动态改变大小

<template>
	<div>
		<div id="myChart" style="width: 100%;height: 90vh;"></div>
	</div>
</template>


<script>
	export default {
		data() {
			return {
				option_column: {
					backgroundColor: '#0f375f',
					title: [{
							text: "各渠道投诉占比",
							x: '2%',
							y: '1%',
							textStyle: {
								color: "#fff",
								fontSize: "14"
							}
						},
						{
							text: "投诉原因TOP10",
							x: '40%',
							y: '1%',
							textStyle: {
								color: "#fff",
								fontSize: "14"
							}
						},
						{
							text: "各级别投诉占比",
							x: '2%',
							y: '50%',
							textStyle: {
								color: "#fff",
								fontSize: "14"
							}
						},
					],
					grid: [{
						x: '50%',
						y: '7%',
						width: '45%',
						height: '90%'
					}, ],
					tooltip: {
						formatter: '{b} ({c})'
					},
					xAxis: [{
						gridIndex: 0,
						axisTick: {
							show: false
						},
						axisLabel: {
							show: false
						},
						splitLine: {
							show: false
						},
						axisLine: {
							show: false
						}
					}, ],
					yAxis: [{
						gridIndex: 0,
						interval: 0,
						data: ['原因1', '原因2', '原因3', '原因4', '原因5', '原因6', '原因7', '原因8', '原因9', '原因10'].reverse(),
						axisTick: {
							show: false
						},
						axisLabel: {
							show: true
						},
						splitLine: {
							show: false
						},
						axisLine: {
							show: true,
							lineStyle: {
								color: "#6173a3"
							}
						},
					}],
					series: [{
							name: '各渠道投诉占比',
							type: 'pie',
							radius: '30%',
							selectedMode: 'single',
							center: ['22%', '25%'],
							color: ['#86c9f4', '#4da8ec', '#3a91d2', '#005fa6', '#315f97'],
							data: [{
									value: 335,
									name: '客服电话'
								},
								{
									value: 310,
									name: '奥迪官网'
								},
								{
									value: 234,
									name: '媒体曝光'
								},
								{
									value: 135,
									name: '质检总局'
								},
								{
									value: 105,
									name: '其他'
								},
							],
							labelLine: {
								normal: {
									show: false
								}
							},
							itemStyle: {
								normal: {
									label: {
										show: true,
										formatter: '{b} \n ({d}%)',
										textStyle: {
											color: '#B1B9D3'
										}
									}
								},
							},
						},
						{
							name: '各级别投诉占比',
							type: 'pie',
							radius: '30%',
							selectedMode: 'single',
							center: ['22%', '75%'],
							color: ['#86c9f4', '#4da8ec', '#3a91d2', '#005fa6', '#315f97'],
							labelLine: {
								normal: {
									show: false
								}
							},
							data: [{
									value: 335,
									name: 'A级'
								},
								{
									value: 310,
									name: 'B级'
								},
								{
									value: 234,
									name: 'C级'
								},
								{
									value: 135,
									name: 'D级'
								},
							],
							itemStyle: {
								normal: {
									label: {
										show: true,
										formatter: '{b} \n ({d}%)',
										textStyle: {
											color: '#B1B9D3'
										}
									}
								},
							},
						},
						{
							name: '投诉原因TOP10',
							type: 'bar',
							xAxisIndex: 0,
							yAxisIndex: 0,
							selectedMode: 'single',
							barWidth: '45%',
							itemStyle: {
								normal: {
									color: '#86c9f4'
								}
							},
							label: {
								normal: {
									show: true,
									position: "right",
									textStyle: {
										color: "#9EA7C4"
									}
								}
							},
							data: [389, 259, 262, 324, 232, 176, 196, 214, 133, 370].sort(),
						},
					]
				}
			};
		},
		watch: {

		},
		mounted() {
			this.showEcharts()
		},
		methods: {
			showEcharts() {
				// 基于准备好的dom,初始化echarts实例
				let myChart = this.$echarts.init(document.getElementById('myChart'))
				// 清除上次记录
				myChart.clear()
				
				// 绘制图表
				myChart.setOption(this.option_column);
				
				// 添加点击事件
				myChart.on("click",this.chartClick)
				
				// 浏览器缩放时动态改变大小
				window.onresize = myChart.resize
				// 或者触发什么事件时刷新图的大小
                // let myChart = this.$echarts.init(document.getElementById('myChart'))
                // myChart.resize()
			},
			chartClick(p){
				// 点击图元回调方法
			}
		}
	}
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 echarts 地图中添加自定义图标并为其添加点击事件,可以按照以下步骤进行操作: 1. 在地图上添加自定义图标 使用 echarts 提供的 `graphic` 组件,可以在地图上添加自定义图标。例如,要在地图上添加一个名为 `myIcon` 的自定义图标,可以使用以下代码: ``` option = { series: [{ type: 'map', map: 'china', ... // 其他配置项 graphic: [{ type: 'image', id: 'myIcon', z: 10, left: 100, top: 100, bounding: 'raw', style: { image: 'path/to/myIcon.png', width: 50, height: 50, }, onclick: function () { // 处理自定义图标点击事件 } }] }] } ``` 在这段代码中,我们使用 `graphic` 组件的 `image` 类型来添加自定义图标,其中 `id` 属性为 `myIcon`,表示该图标的唯一标识符;`z` 属性为 10,表示该图标的层级为 10,即位于所有地图元素的上层;`left` 和 `top` 属性表示该图标的位置;`style` 属性指定了该图标的样式,包括图片路径、宽度和高度;`onclick` 属性为该图标添加点击事件。 2. 处理自定义图标点击事件 当用户点击自定义图标时,我们需要处理该图标点击事件。在上面的代码中,我们已经为自定义图标添加了 `onclick` 属性,该属性指定了点击事件的处理函数。在处理函数中,可以编写自己的业务逻辑,例如弹出一个提示框、展示相关数据等。 例如,以下代码展示了一个简单的处理函数,当用户点击自定义图标时,弹出一个提示框: ``` onclick: function () { alert('您点击了自定义图标!'); } ``` 注意,在处理自定义图标点击事件时,需要注意以下几点: - 点击事件处理函数中的 `this` 关键字指向的是自定义图标的 `graphic` 对象,而不是 echarts 实例或其它对象。 - 如果需要在点击事件处理函数中获取到 echarts 实例或其它对象,可以使用 `myChart` 或 `echarts` 全局变量来访问它们。例如,要获取 echarts 实例,可以使用以下代码: ``` var myChart = echarts.init(document.getElementById('myChart')); myChart.on('click', 'graphic', function (params) { var echartsInstance = myChart.getEchartsInstance(); // ... }); ``` 在上面的代码中,我们使用 `echarts.init` 方法创建了一个 echarts 实例,并将其挂载到一个 HTML 元素上;然后使用 `myChart.on` 方法为该 echarts 实例添加了一个 `click` 事件的监听器,当用户点击地图上的任何元素时,都会触发该监听器;在监听器的处理函数中,我们可以使用 `myChart.getEchartsInstance` 方法获取到 echarts 实例,并对其进行操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值