echarts热力图点击事件带自定义参数

 echarts热力图点击事件带自定义参数,根据官网示例修改了一下,仅供参考~

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>热力图</title>
	</head>
	<body>
		<div id="echarsID" style="height: 400px;"></div>
	</body>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js" type="text/javascript" charset="utf-8"></script>
	<!-- echars版本可以使用自己的 -->
	<script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.0.1/echarts.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function showEchars() {
			var chartDom = document.getElementById('echarsID');
			var myChart = echarts.init(chartDom);
			var option;
            //横坐标name
			var hours = ['1a', '2a', '3a', '4a', '5a', '6a'];
            //纵坐标name
			var days = ['Saturday', 'Friday', 'Thursday', 'Wednesday', 'Tuesday', 'Monday', 'Sunday'];

			var data = [{
					customParam1: "自定义参数1",
					//[x坐标, y坐标, value值]
					value: [0, 1, 2],
					customParam2: "自定义参数2-1"
				},
				{
					customParam1: "自定义参数2",
					value: [0, 2, 5],
					customParam2: "自定义参数2-2"
				},
				{
					customParam1: "自定义参数3",
					value: [1, 1, 0],
					customParam2: "自定义参数2-3"
				},
				{
					customParam1: "自定义参数4",
					value: [1, 2, 7],
					customParam2: "自定义参数2-4"
				},
				{
					customParam1: "自定义参数5",
					value: [2, 3, 8],
					customParam2: "自定义参数2-5"
				},
				{
					customParam1: "自定义参数6",
					value: [2, 5, 2],
					customParam2: "自定义参数2-6"
				},
				{
					customParam1: "自定义参数7",
					value: [3, 1, 1],
					customParam2: "自定义参数2-7"
				},
				{
					customParam1: "自定义参数8",
					value: [3, 4, 1],
					customParam2: "自定义参数2-8"
				},
				{
					customParam1: "自定义参数9",
					value: [4, 3, 1],
					customParam2: "自定义参数2-9"
				},
				{
					customParam1: "自定义参数10",
					value: [5, 2, 1],
					customParam2: "自定义参数2-10"
				}
			];
			option = {
				title: {
					text: "热力图点击事件带自定义参数",
					left: 'center',
					top:'2%'
				},
				tooltip: {
					position: 'top'
				},
				grid: {
					height: '50%',
					top: '10%'
				},
				xAxis: {
					type: 'category',
					data: hours,
					splitArea: {
						show: true
					}
				},
				yAxis: {
					type: 'category',
					data: days,
					splitArea: {
						show: true
					}
				},
				visualMap: {
					min: 0,
					max: 10,
					calculable: true,
					orient: 'horizontal',
					left: 'center',
					bottom: '15%'
				},
				series: [{
					name: 'Punch Card',
					type: 'heatmap',
					data: data,
					label: {
						show: true
					},
					emphasis: {
						itemStyle: {
							shadowBlur: 10,
							shadowColor: 'rgba(0, 0, 0, 0.5)'
						}
					}
				}]
			};
			option && myChart.setOption(option);
			//热力图点击事件
			myChart.off('click');
			myChart.on('click', function(e) {
				console.log(e)
				console.log(e.data.customParam1,e.data.customParam2)
			});
		}
		//调用方法
		showEchars()
	</script>
</html>

效果图:

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值