单击子项Highcharts时获取父项

时间:2016-05-04 10:30:10

标签: javascript highcharts

我遇到问题是高图,这是我的代码:

              categories = ['Position', 'Ages', 'Salary'],
                    data = [{
                        y: 120,
                        color: colors[0],
                        drilldown: {
                            name: 'Position',
                            categories: dataemp,
                            data: percent,                           
                            color: colors[1]
                        }
                    }, {
                        y: 120,
                        color: colors[4],
                        drilldown: {
                            name: 'Ages',
                            categories: ['10-20', '20-30', '30-40', '40-50', '50-60'],
                            data: [parseFloat(age[0]['percentA']), parseFloat(age[0]['percentB']), parseFloat(age[0]['percentC']), parseFloat(age[0]['percentD']), parseFloat(age[0]['percentE'])],
                            color: colors[2]
                        }
                    }

我想显示父名称,当我点击子项时,例如子名称为10-20。我需要的输出如下:
This 10-20 has parent : Ages
帮帮我谢谢。

1 个答案:

答案 0 :(得分:1)

 series: [{
            name: 'Items',
            colorByPoint: true,
            data: [{
                name: 'Position',
                y: 5,
                drilldown: 'position'
            }, {
                name: 'Ages',
                y: 2,
                drilldown: 'ages'
            }, {
                name: 'Salary',
                y: 4,
                drilldown: 'salary'
            }]
        }],
        drilldown: {
            series: [{
                id: 'position',
                data: [
                    ['position1', 50],
                    ['position2', 60],
                    ['position3', 25]
                ]
            }, {
                id: 'ages',
                data: [
                    ['10-20', 20],
                    ['20-30', 30],
                    ['30-40', 50],
                    ['40-50', 60],
                    ['50-60', 25]
                ]
            }, {
                id: 'salary',
                data: [
                    ['salary1', 50000],
                    ['salary2', 20000],
                    ['salary3',10000]
                ]
            }]

检查这个小提琴,http://jsfiddle.net/6fLhxy00/