echarts 柱状图点击事件

<body>
	<div style="margin: 0;padding: 5px;">
		<div id="main" style="width: 100%;height:228px;"></div>
	</div>
</body>

// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
	grid: {    
		left: '5%',
		   //距离左边的距离
		    right: '5%', //距离右边的距离
		    bottom: '10%', //距离下边的距离
		    top: '12%', //距离上边的距离
		    
	},
	title: {
		text: data.n + '年',
		x: 'right',
		textStyle: {
			fontSize: 12,
			color: '#777'
		}
	},
	tooltip: {
		show: true, //隐藏鼠标点击后的提示
	},
	legend: {
		data: ['总额:' + data.count + '元'],
		itemWidth: 10,
		x: 'left',
		textStyle: { //图例文字的样式
			color: '#FF6353',
		},
	},
	xAxis: {
		data: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
		axisLabel: {
			interval: 0, //x轴文字显示完整(不保证)
			rotate: 0, //倾斜角度搭配上面行显示完全
			textStyle: {
				fontSize: 12,
				color: '#aaa'
			}
		},
		axisLine: {
			//设置地名及x轴线条颜色
			show: true,
			lineStyle: {
				color: '#aaa',
			}
		}
	},
	yAxis: {
		show: false,
	},
	series: [{
		name: '总额:' + data.count + '元',
		type: 'bar',
		data: data.data,
		barWidth: '18', //柱形宽度
		// 普通样式。
		itemStyle: {
        // 高亮样式。
		emphasis: {
			itemStyle: {
				// 高亮时点的颜色。
				color: '#62A7D1',
			}
		},
			normal: {
				//柱形图圆角,初始化效果
				barBorderRadius: [3, 3, 0, 0],
				// 点的颜色。
				color: '#A1CAE3',
			}
		},
		// 高亮样式。
		emphasis: {
			itemStyle: {
				// 高亮时点的颜色。
				color: '#62A7D1',
			}
		},
		label: {
			normal: {
				show: true, //显示数字
				position: 'top', //这里可以自己选择位置
				textStyle: {
					color: '#aaa', //文字颜色
					fontSize: 12,
				}
			}
		}
	}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);

//点击事件
myChart.on('click', function(params) {
    console.log(params); 
	var name = parseInt(params.name);
});

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值