使用Highcharts单击饼图切片时,是否可以指定不同的半径?

时间:2018-01-22 12:38:53

标签: highcharts

我正在使用Highcharts它工作正常,但是当我点击单个饼图切片然后该切片重叠两个切片(右边或左边切片)时,我想更改饼图切片。

以下是我在饼图中所做的图片。 enter image description here

以下是附加的饼图结果附带的图像 enter image description here

2 个答案:

答案 0 :(得分:4)

您可以添加自己的方法,该方法会在点击时调整形状大小,例如:http://jsfiddle.net/BlackLabel/8vd6cod1/

function resizeSlice(point, change) {
  // Original shape params are stored in shapeArgs:
  var shape = point.shapeArgs;

  if (point.graphic) {
    point.graphic.attr({
      // "r" is outer radius:
      r: shape.r + change,
      // "innerR" is inner radius:
      innerR: shape.innerR - change
    });
  }
}

// Build the chart
Highcharts.chart('container', {
  chart: {
    type: 'pie',
    events: {
      // On window resize, apply change:
      redraw: function() {
        Highcharts.each(this.series[0].points, function(point) {
          resizeSlice(point, point.customResized ? 5 : 0)
        });
      }
    }
  },
  plotOptions: {
    pie: {
      innerSize: '90%',
      cursor: 'pointer',
      dataLabels: {
        enabled: false
      },
      point: {
        events: {
          click: function() {
            var change = 0;
            // Custom param, can be called whatever we want:
            this.customResized = !this.customResized;

            if (this.customResized) {
              // Let's resize!
              change = 5;
            }

            resizeSlice(this, change);
          }
        }
      }
    }
  },
  series: [{
    data: [3, 4, 5, 6]
  }]
});

答案 1 :(得分:-2)

我已经对此代码进行了一些更改,以便重新调整所有其他饼图。

http://jsfiddle.net/8vd6cod1/2/

function resizeSlice(point, change) {
  // Original shape params are stored in shapeArgs:
  var shape = point.shapeArgs;

  if (point.graphic) {
    point.graphic.attr({
      // "r" is outer radius:
      r: shape.r + change,
      // "innerR" is inner radius:
      innerR: shape.innerR - change
    });
  }
}

// Build the chart
Highcharts.chart('container', {
  chart: {
    type: 'pie',
    events: {
      // On window resize, apply change:
      redraw: function() {
        Highcharts.each(this.series[0].points, function(point) {
          resizeSlice(point, point.customResized ? 5 : 0)
        });
      }
    }
  },
  plotOptions: {
    pie: {
      innerSize: '90%',
      cursor: 'pointer',
      dataLabels: {
        enabled: false
      },
      point: {
        events: {
          click: function() {
            Highcharts.each(this.series.points, function(point) {
               resizeSlice(point, 0)
            });
            var change = 0;
            // Custom param, can be called whatever we want:
            this.customResized = !this.customResized;

            if (this.customResized) {
              // Let's resize!
              change = 5;
            }

            resizeSlice(this, change);
          }
        }
      }
    }
  },
  series: [{
    data: [3, 4, 5, 6]
  }]
});