Highcharts pie chart - offset a single slice on legend click

陌路散爱 提交于 2019-12-12 03:19:08

问题


I've been searching through the API docs and lots of examples, but can't seem to find what I want.

I have a pie chart with a legend. When you click a slice, it becomes offset (this is great). I would like this behaviour when you click on a legend item.

Is it possible to achieve an offset slice via legend click?

So if you click on an item in the legend, the relevant slice becomes offset.

It seems that the method to use is legendItemClick, eg:

options: {
     chart: {
         type: 'pie'
     },
     plotOptions: {

      //etc

      series: {
        point: {
          events: {

            legendItemClick: function () {

              //return false; // this cancels the default action.

              console.log(this);

              //this.findtheSlice.makeItOffset();  //want to do something like this

            }

          }
        }
      }

    //etc

    }
  }
}

Here is a JSFiddle

It seems that there isn't a method available to achieve this so may need to go deep into the api.

Any help would be very appreciated!

Btw, i'm using an angular directive for highcharts (highcharts-ng). There are some subtle differences.


回答1:


In the legendItemClick you should call this.slice() and then return false.

           point: {
                events: {
                    legendItemClick: function () {
                        this.slice();
                        return false;
                    }
                }
            },

Example: http://jsfiddle.net/95n2mm02/4/



来源:https://stackoverflow.com/questions/32526109/highcharts-pie-chart-offset-a-single-slice-on-legend-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!