HighCharts Stacked Column Adding Onclick Event to the chart

user6734960

I am working on a Highchart column chart.

I need to add an onclick event to it so I can get data back when I click on the different columns.

Here is my current full code.

var chart;

    $(function () {

      $.ajax({

            url: 'url here',
            method: 'GET',
            async: false,
            success: function(result) { 

                themainData = result;

            }
      });


      var mainData = [themainData];
      var chList=[];
      var voList=[];
      var coList=[];

      for (var i = 0; i < mainData[0].ch.length; i++) {

        var obj = mainData[0].ch[i];

        var chlst = obj.name;
        var vl = obj.st.vo;
        var cl = obj.st.co;

        chList.push(chlst);
        voList.push(vl); 
        coList.push(cl); 

      }

      var chart = {
          type: 'column',
       };

       var title = {
          text: 'Vo and Co'   
       };    

       var xAxis = {
          categories: chList
       };

       var yAxis ={
          min: 0,
          title: {
            text: 'Ch'
          },
          stackLabels: {
            enabled: true,
            style: {
               fontWeight: 'bold',
               color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
            }
          }
       };

       var legend = {
          align: 'right',
          x: -30,
          verticalAlign: 'top',
          y: 25,
          floating: true,
          backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
          borderColor: '#CCC',
          borderWidth: 1,
          shadow: false
       }; 

       var tooltip = {
          formatter: function () {
             return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
          }
       };

       var plotOptions = {
          column: {
             stacking: 'normal',
             dataLabels: {
                enabled: true,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                style: {
                   textShadow: '0 0 3px black'
                }
             }
          }
       };

       var credits = {
          enabled: false
       };

       var series= [{
            name: 'Vo',
                data: voList
            }, {
                name: 'Co',
                data: coList    
       }];     

       var json = {};   
       json.chart = chart; 
       json.title = title;   
       json.xAxis = xAxis;
       json.yAxis = yAxis;
       json.legend = legend;
       json.tooltip = tooltip;
       json.plotOptions = plotOptions;
       json.credits = credits;
       json.series = series;

       $('#container').highcharts(json);


    });

Where do I add the onclick event here?

Barbara Laird

You can add the click event on the chart, series, or point. I think it makes sense in your case to add the click event to the series.

 var series= [{
        name: 'Vo',
        data: voList
        events: {
            click: function (event) {}
        }
    }, {
        name: 'Co',
        data: coList    
   }];  

event.point is the point that is clicked on. See http://api.highcharts.com/highcharts/series%3Cbar%3E.events.click

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Highcharts tooltip bug with stacked column chart

From Dev

How to modify Column stacked percent Chart in Highcharts

From Dev

stacked group column chart in highcharts example

From Dev

Pass data to Stacked Column Chart (Highcharts Framework)

From Dev

Stacked Column Chart With Unequal SubGroups in HighCharts.js

From Dev

HighCharts stacked column range

From Dev

Highcharts overlapping and stacked column

From Dev

HighCharts stacked column range

From Dev

HighCharts: Drilldown to a Stacked Column

From Dev

Highcharts drilldown in stacked area chart

From Dev

Grouping a stacked bar chart in Highcharts

From Dev

Highcharts - Detail chart with stacked columns

From Dev

Grouped and Stacked Column Chart

From Dev

Stacked column chart in Excel

From Dev

Adding round corners to Highcharts Bar Chart with stacked bars when value is 0

From Dev

Highcharts stacked column bar with line

From Dev

Highcharts datalabel for each stacked column

From Dev

Highcharts Stacked Percentage Column Hyperlink

From Dev

Highcharts Stacked Percentage Column Hyperlink

From Dev

Highcharts 4.0.3 stacked bar chart bug adds â-

From Dev

HighCharts stacked grouped chart - with grouped caregories plugin

From Dev

Highcharts column chart grouping

From Dev

Issue with creating stacked column chart

From Dev

HighChart: Stacked Column Chart with dropdown

From Dev

Issue with creating stacked column chart

From Dev

SSRS stacked column chart legend is Wrong after adding lookset() inside the Action

From Dev

Trouble adding scatter plot markers (total) to a vertical stacked column chart (components)

From Dev

Turn a stacked column google chart into a waterfall chart

From Dev

render a circle onclick event in highcharts

Related Related

  1. 1

    Highcharts tooltip bug with stacked column chart

  2. 2

    How to modify Column stacked percent Chart in Highcharts

  3. 3

    stacked group column chart in highcharts example

  4. 4

    Pass data to Stacked Column Chart (Highcharts Framework)

  5. 5

    Stacked Column Chart With Unequal SubGroups in HighCharts.js

  6. 6

    HighCharts stacked column range

  7. 7

    Highcharts overlapping and stacked column

  8. 8

    HighCharts stacked column range

  9. 9

    HighCharts: Drilldown to a Stacked Column

  10. 10

    Highcharts drilldown in stacked area chart

  11. 11

    Grouping a stacked bar chart in Highcharts

  12. 12

    Highcharts - Detail chart with stacked columns

  13. 13

    Grouped and Stacked Column Chart

  14. 14

    Stacked column chart in Excel

  15. 15

    Adding round corners to Highcharts Bar Chart with stacked bars when value is 0

  16. 16

    Highcharts stacked column bar with line

  17. 17

    Highcharts datalabel for each stacked column

  18. 18

    Highcharts Stacked Percentage Column Hyperlink

  19. 19

    Highcharts Stacked Percentage Column Hyperlink

  20. 20

    Highcharts 4.0.3 stacked bar chart bug adds â-

  21. 21

    HighCharts stacked grouped chart - with grouped caregories plugin

  22. 22

    Highcharts column chart grouping

  23. 23

    Issue with creating stacked column chart

  24. 24

    HighChart: Stacked Column Chart with dropdown

  25. 25

    Issue with creating stacked column chart

  26. 26

    SSRS stacked column chart legend is Wrong after adding lookset() inside the Action

  27. 27

    Trouble adding scatter plot markers (total) to a vertical stacked column chart (components)

  28. 28

    Turn a stacked column google chart into a waterfall chart

  29. 29

    render a circle onclick event in highcharts

HotTag

Archive