zoukankan      html  css  js  c++  java
  • angular11给Echarts添加点击事件,无脑抄代码的时候到了~~ 超好用

    关于引入Echarts的方法在此

    直通车在此

    接下来就是添加点击事件,获取X轴的数据

    
    <div echarts #charts [options]="chartOption" class="charts"></div>
    
    import { NgxEchartsService } from 'ngx-echarts';
      @ViewChild('charts', { static: false }) charts: ElementRef;
    constructor(
        private es: NgxEchartsService
      ) { }
    
    this.es.getInstanceByDom(this.charts.nativeElement).setOption(this.chartOption)
     let myChart = this.es.getInstanceByDom(this.charts.nativeElement)
          myChart.getZr().on('click', function (params) {
            var pointInPixel = [params.offsetX, params.offsetY];
            if (myChart.containPixel('grid', pointInPixel)) {
              /*此处添加具体执行代码*/
              var pointInGrid = myChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel);
              //X轴序号
              var xIndex = pointInGrid[0];
              //获取当前图表的option
              var op = myChart.getOption();
              //获得图表中我们想要的数据---懒得写循环了,复制了一下,下面就不简写了,默认说我们的折现有三条吧
              var xValue = op.xAxis[0].data[xIndex];
              var value = op.series[0].data[xIndex];
              var name = op.series[0].name;
              var value1 = op.series[1].data[xIndex];
              var name1 = op.series[1].name;
              var value2 = op.series[2].data[xIndex];
              var name2 = op.series[2].name;
              console.log(op);
              console.log('xValue: '+xValue + ", series[0].name0: "+name +' , value: '+ value + "%");
              console.log('xValue: '+xValue + ", series[1].name0: "+name1 +' , value1: '+ value1 + "%");
              console.log('xValue: '+xValue + ", series[2].name0: "+name2 +' , value2: '+ value2 + "%");
            }
          });
    
  • 相关阅读:
    Java实现OPC通信
    OPCServer:使用KEPServer
    OPCServer:使用Matrikon OPC Server Simulation
    OPC和DCOM配置
    jquery中attr和prop的区别
    jquery 操作checkbox是否选中的正确方法
    GPRS RTU设备OPC Server接口C# 实现
    Raspberry Pi 中安装Mono
    C#中DllImport用法汇总
    HTML <form> 标签的 method 属性
  • 原文地址:https://www.cnblogs.com/sugartang/p/14847529.html
Copyright © 2011-2022 走看看