简体   繁体   English

如何在用户单击时确定条形图(Highchart)中条形的值?

[英]How to I determine the value of a bar in a bar chart (Highchart) on user click?

Currently I have a Highchart that renders according to data in my database. 目前,我有一个Highchart,可以根据数据库中的数据进行渲染。 I also currently have a table that renders with the correct values when I pass in a value such as "A" or "C" manually, but I'd like the table to render according to an onClick event, when a user clicks on a bar in my Highchart. 我目前还拥有一个表,当我手动传递诸如“ A”或“ C”之类的值时,该表将显示正确的值,但是我希望该表根据onClick事件(当用户单击一个我的Highchart中的酒吧。

For each corresponding value below, such as @a_sum, I have an array called @a with string values in it that will be passed into the chart. 对于下面的每个对应值,例如@a_sum,我有一个名为@a的数组,其中包含字符串值,该数组将传递到图表中。

I've Googled around without much luck. 我在Google周围没有很多运气。 I'm wondering how I get the value of the bar in the char when a user clicks on that specific bar. 我想知道当用户单击特定栏时如何获得char中的栏值。

Any help would be hugely appreciated. 任何帮助将不胜感激。

<script type="text/javascript" charset="utf-8">
var chart1; // globally available
$(document).ready(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'bar'
        },
        title : {
            text: "Most Effective Referral Sources"
        },
        xAxis: {
            categories: ['A', 'B', 'C', 'D', 'E', 'F',  'G', 'H', 'I', 'J', 'K', 'L']
        },
        yAxis: {   
        },
        legend: {
            layout: 'vertical',
            floating: true,
            backgroundColor: '#FFFFFF',
            align: 'right',
            verticalAlign: 'top',
            y: 60,
            x: -60
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y;
            }
        },
        plotOptions: {
        },
        series: [{
            data: [<%= @a_sum %>, <%= @b_sum %>, <%= @c_sum %>, <%= @d_sum %>,  <%= @e_sum %>, <%= @f_sum %>, <%= @g_sum %>, <%= @h_sum %>, <%= @i_sum %>, <%= @j_sum %>,  <%= @k_sum %>, <%= @l_sum %>]
        }]
    });
});

</script>

It seems like what you want (if I understand you question correctly) is to implement the event in the plotOptions above: http://www.highcharts.com/ref/#plotOptions-column-point-events--click 似乎您想要的(如果我理解正确的话)是在上述plotOptions中实现该事件: http ://www.highcharts.com/ref/#plotOptions-column-point-events--click

plotOptions: {
    column: {
         point: {
             events: {
         click: function() {
                     // use this to trigger showing/hiding the specific table you need
                     console.log(this)
                 }
             }
         }
    }
}

For example, this is a sample of the console log I got: 例如,这是我得到的控制台日志的示例:

Lc
_high: 417
...
series: c
...
x: 20
y: 33
__proto__: Object

With this.series you should be able to get the parameters on the series whose column you click, and then call your "enableTableForDataSeries" function to enable the specific data series. 使用this.series,您应该能够获得其单击列的系列的参数,然后调用“ enableTableForDataSeries”函数来启用特定的数据系列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM