Highcharts ---在钻取饼图上更改切片颜色

时间:2014-11-07 20:51:38

标签: highcharts pie-chart drilldown

我正在尝试更改饼图上的切片点颜色。向下钻取时,使用切片上的选择功能无法更改颜色。颜色始终更改回其父切片的颜色。

例如,当在父图表上单击绿色切片以向下钻取时,单击子图表上的任何切片都将变为绿色,即使我尝试在plotOptions中设置的select事件中将其更改为黄色。但是通过单击另一个切片,取消选择它会将颜色更改为黄色。

这对我来说似乎是个错误。

       $('#container').highcharts({
            chart: {
                type: 'pie'
            },
            title: {
                text: 'Browser market shares. November, 2013.'
            },
            subtitle: {
                text: 'Click the slices to view versions. Source: netmarketshare.com.'
            },
            plotOptions: {
                series: {
                    allowPointSelect: true,
                    point: {
                        events: {
                          select: function() {
                            this.update({color: 'yellow'});
                          }
                        }
                    },
                    dataLabels: {
                        enabled: true,
                        format: '{point.name}: {point.y:.1f}%'
                    }
                }
            },

            tooltip: {
                headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
            },

            series: [{
                name: 'Brands',
                colorByPoint: true,
                data: brandsData
            }],
            drilldown: {
                series: drilldownSeries
            }
        });

Here是小提琴。

2 个答案:

答案 0 :(得分:1)

在当前版本的Highcharts(Highcharts Basic v7.2.1 )中,所有功能均正常运行。

答案 1 :(得分:0)

我在这方面有点迟了,但这是Highcharts的已知问题。代替使用select事件,而使用selected和unselected事件。这里有一个细微的差别,因为使用select常常不会在单击后立即触发。但是,这两个事件更加可靠。

https://api.highcharts.com/highcharts/plotOptions.pie.point.events.select https://api.highcharts.com/highcharts/plotOptions.pie.point.events.unselect