代码之家  ›  专栏  ›  技术社区  ›  Ethan Arti Singh

事件中键单击饼图切片?

  •  1
  • Ethan Arti Singh  · 技术社区  · 6 年前

    api documentation 为了它。

    我做这个测试是为了证明 console.log 当你中击一个切片,但是有一个 当你 控制 点击 ,或常规 点击

    $(function () {
        $('#container').highcharts({
            chart: {
                type: 'pie'
            },
            
            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                console.log('clicked on y: ' + this.y);
                            },
                        }
                    }
                }
            },
            
            series: [{
                data: [{
                    y: 29.9
                }, {
                    y: 71.5
                }, {
                    y: 106.4
                }]        
            }]
        });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    
    <div id="container" style="height: 400px"></div>

    当我中键单击饼图切片时,是否有方法触发事件?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Ashu    6 年前

    highchart提供的其他默认事件 click ,也可以在容器上附加事件。如果你是这样的话 mousedown

    Attach event to container

    $(function () {
        $('#container').highcharts({
            chart: {
                type: 'pie'
            },
            
            plotOptions: {
                series: {
                    cursor: 'pointer',                
                }
            },
            
            series: [{
                data: [{
                    y: 29.9
                }, {
                    y: 71.5
                }, {
                    y: 106.4
                }]        
            }]
        });
    });
    
    $(document).on('mousedown', '#container path', function (e) {
        if(e.which==2)
         console.log('Middle click on slice '+e.target.point.x+ " value is "+e.target.point.y);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    
    <div id="container" style="height: 400px"></div>