How to add table on click over each column in Highcharts

300 Views Asked by At

I am using highcharts as for using the charts drilldown. I can display the column graph which has a drilldown. The requirement is after clicking over each column, a table related to that column's detailed information needs to be displayed with some data concerning that barchart below the chart. I am unable to create that Table. Would like to prefer ant table, but any table is appreciated, and would like to close the table with a close button. Can someone please help me with this? Thank you

<script src="http://github.highcharts.com/highcharts.js"></script>
<script src="http://github.highcharts.com/modules/drilldown.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

$(function () {    

    // Create the chart
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Basic drilldown'
        },
        xAxis: {
            type: 'category'
        },

        legend: {
            enabled: true
        },

        plotOptions: {
            series: {
                borderWidth: 0,
                dataLabels: {
                    enabled: true,
                    style: {
                        color: 'white',
                        textShadow: '0 0 2px black, 0 0 2px black'
                    }
                },
                stacking: 'normal'
            }
        },

        series: [{
            name: 'Things',
            data: [{
                name: 'Animals',
                y: 5,
                drilldown: 'animals'
            }, {
                name: 'Fruits',
                y: 2,
                drilldown: 'fruits'
            }, {
                name: 'Cars',
                y: 4,
                drilldown: 'cars'
            }]
        }, {
            name: 'Things2',
            data: [{
                name: 'Animals',
                y: 1,
                drilldown: 'animals2'
            }, {
                name: 'Fruits',
                y: 5,
                drilldown: 'fruits2'
            }, {
                name: 'Cars',
                y: 2,
                drilldown: 'cars2'
            }]
        }],
        drilldown: {
            activeDataLabelStyle: {
                color: 'white',
                textShadow: '0 0 2px black, 0 0 2px black'
            },
            series: [{
                id: 'animals',
                name: 'Animals',
                data: [
                    ['Cats', 4],
                    ['Dogs', 2],
                    ['Cows', 1],
                    ['Sheep', 2],
                    ['Pigs', 1]
                ]
            }, {
                id: 'fruits',
                name: 'Fruits',
                data: [
                    ['Apples', 4],
                    ['Oranges', 2]
                ]
            }, {
                id: 'cars',
                name: 'Cars',
                data: [
                    ['Toyota', 4],
                    ['Opel', 2],
                    ['Volkswagen', 2]
                ]
            },{
                id: 'animals2',
                name: 'Animals2',
                data: [
                    ['Cats', 3],
                    ['Dogs', 5],
                    ['Cows', 6],
                    ['Sheep', 2],
                    ['Pigs', 2]
                ]
            }, {
                id: 'fruits2',
                name: 'Fruits2',
                data: [
                    ['Apples', 1],
                    ['Oranges', 5]
                ]
            }, {
                id: 'cars2',
                name: 'Cars2',
                data: [
                    ['Toyota', 2],
                    ['Opel', 3],
                    ['Volkswagen', 2]
                ]
            }]
        }
    })
});

Added the code here. I would like to see the table when you click on the drilldown and click either cats to show a table with with all the cats.

1

There are 1 best solutions below

2
Sebastian Hajdus On

You can start from here to make table in HTML, and inside chart.events.drilldown to control content in tables.

  chart: {
    type: 'column',
    events: {
      drilldown: function(e) {
        if (e.point.name === 'Animals') {
          firstDiv.style.display = 'block';
          secondDiv.style.display = 'none';
          thirdDiv.style.display = 'none';
        } else if (e.point.name === 'test') {
          secondDiv.style.display = 'block';
          firstDiv.style.display = 'none';
          thirdDiv.style.display = 'none';
        } else if (e.point.name === 'test2') {
          thirdDiv.style.display = 'block';
          firstDiv.style.display = 'none';
          secondDiv.style.display = 'none';
        }

        setTimeout(function() {
          chart.setSize(300);
        }, 0);
      },
      drillup: function() {
        firstDiv.style.display = 'none';
        secondDiv.style.display = 'none';
        thirdDiv.style.display = 'none';

        this.setSize(null, null);
      }
    }
  },

Demo: https://jsfiddle.net/BlackLabel/jqcpv6ox/