修改
This commit is contained in:
@@ -62,23 +62,33 @@ export default {
|
||||
console.error('图表容器未找到!');
|
||||
return;
|
||||
}
|
||||
|
||||
// 只创建一次图表实例
|
||||
this.myChart = echarts.init(chartDom);
|
||||
this.myChart.getZr().on('click', (params) => {
|
||||
console.log('params', params);
|
||||
|
||||
// 绑定点击事件(只绑定一次,永久生效)
|
||||
this.myChart.on('click', (params) => {
|
||||
// 提取点击的基地名称
|
||||
const itemName = params.name;
|
||||
// const itemName = params.name;
|
||||
let itemName = undefined
|
||||
// 根据映射表获取对应的序号(未匹配到则返回0或其他默认值)
|
||||
let pointInPixel = [params.offsetX, params.offsetY];
|
||||
if (this.myChart.containPixel('grid', pointInPixel)) {
|
||||
let pointInGrid = this.myChart.convertFromPixel({
|
||||
seriesIndex: 0
|
||||
}, pointInPixel);
|
||||
let xIndex = pointInGrid[0]; //索引
|
||||
let handleIndex = Number(xIndex);
|
||||
let seriesObj = this.myChart.getOption(); //图表object对象
|
||||
var op = this.myChart.getOption();
|
||||
//获得图表中点击的列
|
||||
itemName = op.xAxis[0].data[handleIndex]; //获取点击的列名
|
||||
console.log(itemName, 'monthmonthmonth');
|
||||
console.log(handleIndex, seriesObj);
|
||||
};
|
||||
const baseIndex = this.baseNameToIndexMap[itemName] || 0;
|
||||
|
||||
// 兼容不同图表类型的value:柱状图value是数值,折线图是[横坐标, 纵坐标]
|
||||
// const itemValue = Array.isArray(params.value) ? params.value[1] : params.value;
|
||||
// const seriesName = params.seriesName;
|
||||
|
||||
console.log(`你点击了【${itemName}】(序号:${baseIndex})`);
|
||||
|
||||
|
||||
// 路由跳转时携带序号(或名称+序号)
|
||||
this.$router.push({
|
||||
path: 'rawSheetYieldBase',
|
||||
|
||||
Reference in New Issue
Block a user