Highcharts通过allowPointSelect选取多个点

来源:互联网 发布:adobe illustrator mac 编辑:程序博客网 时间:2024/05/23 16:56
1、设置点可选中

设置plotOptions 的 allowPointSelect 为true,表示点可以选中。

2、获取选中的点

通过chart.getSelectedPoints();函数来获取选中的点,该函数返回值是一个数组,包含选中的点的所有信息。

实例代码如下:

<!doctype html><html lang="en"><head>  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>    <script src="http://code.highcharts.com/highcharts.js"></script>  <script>    $(function () {    $('#container').highcharts({        chart: {        },        xAxis: {            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']        },        plotOptions: {            series: {                allowPointSelect: true            }        },        series: [{            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]                }]    });              // the button action    $('#111').click(function() {        // Highcharts构造函数        var chart = $('#container').highcharts(),        // 获取选中的点        selectedPoints = chart.getSelectedPoints();        // 选中个数        alert('You selected '+ selectedPoints.length +' points');                 // 遍历选中的点        $.each(selectedPoints, function(i, point) {                // category x轴值,index x轴下标值,y 轴值            alert("category=" + point.category + ", index=" + point.x+", y="+point.y);        })    });});</script></head><body>  <div id="container" style="min-width:700px;height:400px"></div>  <div style="margin:10px 0px 10px 20px;">      <button id="111">获取选中的点</button>  </div></body></html>

效果图如下:


demo实例下载



0 0
原创粉丝点击