如何在Highcharts中的每一列上单击添加表格

goucqfw6  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(154)

我正在使用highcharts作为使用图表钻取。我可以显示具有钻取的柱形图。要求是在单击每列后,需要显示与该列的详细信息相关的表,并在图表下方显示与该条形图相关的一些数据。我无法创建该表。希望首选ant table,但任何表都很感激。并希望使用关闭按钮关闭表。有人可以帮助我吗?谢谢

<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]
                ]
            }]
        }
    })
});

添加了代码here。我希望在您单击钻取明细并单击任一猫以显示包含所有猫的表时看到该表。

eanckbw9

eanckbw91#

您可以从这里开始在HTML中制作表格,并在chart.events.drilldown内部控制表格中的内容。

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);
      }
    }
  },

演示:https://jsfiddle.net/BlackLabel/jqcpv6ox/

相关问题