javascript - 在 highcharts 上执行单击事件时获取机器人 xAxis 值

标签 javascript jquery charts highcharts

我想设置一个单击事件来获取图表中的 xAxis 值。就我而言,我有两个 xAxis 并且想同时获得它们。目前,在我的示例中,我只能获取最上面的 xAxis 值,当我在图表上执行单击事件时,如何获取这两个值?

js fiddle link

<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 900px"></div>


Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    xAxis: [{

        categories: ['Catagory 1', 'Catagory 2', 'Catagory '],
        labels: {
            style:{
            color: 'red'
            },
            formatter: function () {
                return this.value;
            }
        }
    }, 
        {
                linkedTo: 0,
                categories: ['Dec 4', 'Dec 5', 'Dec 6'],
            }],

        tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },

    plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function() {
                        var tableDate = this.category;
                        console.log(this);
                        alert(tableDate);
                       /*  window.location.href = '/performance_reports_detail'; */

                    }
                }
            }
        }
    },

    series: [{
        name: 'Group Value 1',
        data: [29.9, 71.5, 106.4]
    },
    {
        name: 'Group Value 2',
        data: [50, 71.5, 106.4]
    },
    {
        name: 'Group Value 3',
        data: [21, 71.5, 106.4]
    }]
});

chart pic

object

最佳答案

您可以从类别数组中的右侧元素获取第二个 xAxis 值:

        point: {
            events: {
                click: function() {
                    var tableDate = this.category,
                        secondValue = this.series.chart.xAxis[1].categories[this.x];

                    console.log(tableDate, secondValue);
                }
            }
        }

现场演示:http://jsfiddle.net/BlackLabel/2ge5wzLs/

关于javascript - 在 highcharts 上执行单击事件时获取机器人 xAxis 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462199/

相关文章:

javascript - 何时加载浏览器框架脚本 (e10s)?

javascript - 任意 Google Swiffy Canvas 大小/离屏渲染

jquery - 我想使用 jQuery 获取指向图像的所有链接

javascript - Google 图表 - 在 x 和 y 标签上拉伸(stretch)图表

javascript - 在 Google Line Chart API 中使用字符串作为标签

javascript - 测试使用具有单独模板的另一个组件的 ember 组件

javascript - JavaScript 不会调整 Div 的大小

javascript - 正则表达式用jQuery中的特殊字符替换子字符串

javascript - 通过 ajax 加载 DIV 内容作为 HTML

jquery - 饼中饼( donut )图表