繁体   English   中英

Highcharts数据标签未在饼图中显示每个切片的前面

[英]Highcharts datalabels are not showing infront of each slice in pie chart

我正在使用highcharts并尝试从中绘制饼图,但遇到一个奇怪的问题,我的数据标签未正确显示在切片的前面,并且仅在饼中有10个以上切片时才发生。 我不想显示连接器,我只想在饼图附近显示我的数据标签,并且应该在每个切片的前面正确显示。 我也不想增加饼图的大小。

饼形图

$(function () {
var asset_allocation_pie_chart = new Highcharts.Chart({
    chart: {
        renderTo: 'asset_allocation_bottom_left_div'
    },
    title: {
        text: 'Current Asset Allocation',
        style: {
            fontSize: '17px',
            color: 'red',
            fontWeight: 'bold',
            fontFamily: 'Verdana'
        }
    },
    subtitle: {
        text: '(As of ' + 'dfdf' + ')',
        style: {
            fontSize: '15px',
            color: 'red',
            fontFamily: 'Verdana',
            marginBottom: '10px'
        },
        y: 40
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage}%</b>',
        percentageDecimals: 0
    },
    plotOptions: {
        pie: {
            size: '60%',
            cursor: 'pointer',
            data: [
                ['Investment Grade Bonds', 100],
                ['High Yield Bonds', 200],
                ['Hedged Equity', 300],
                ['Global Equity', 400],
                ['Cash', 500],
                ['Cash', 500],
                ['Hedged Equity', 300],
                ['Global Equity', 400],
                ['Cash', 500],
                ['High Yield Bonds', 200],
                ['Hedged Equity', 300],
                ['Global Equity', 400],
                ['Cash', 500],
                ['High Yield Bonds', 200],
                ['Hedged Equity', 300],
                ['Global Equity', 400],
            ]
        }
    },
    series: [{
        type: 'pie',
        name: 'Asset Allocation',
        dataLabels: {                
            enabled: true,
            color: '#000000',
            connectorWidth: 0,
            distance: 5,
            connectorColor: '#000000',
            formatter: function () {
                return Math.round(this.percentage) + ' %';
            }

        }
    }],
    exporting: {
        enabled: false
    },
    credits: {
        enabled: false
    }
});

});

问题是您正在舍入价值,

尝试这个,

$(function() {
  var asset_allocation_pie_chart = new Highcharts.Chart({
    chart: {
      renderTo: 'container'
    },
    title: {
      text: 'Current Asset Allocation',
      style: {
        fontSize: '17px',
        color: 'red',
        fontWeight: 'bold',
        fontFamily: 'Verdana'
      }
    },
    subtitle: {
      text: '(As of ' + 'dfdf' + ')',
      style: {
        fontSize: '15px',
        color: 'red',
        fontFamily: 'Verdana',
        marginBottom: '10px'
      },
      y: 40
    },

    plotOptions: {
      pie: {
        size: '60%',
        cursor: 'pointer',
        series: {
          dataLabels: {
            enabled: true,
            format: '{point.name}: {point.y:.1f}%'
          }
        }

      }
    },
    series: [{
      type: 'pie',
      name: 'Asset Allocation',

      data: [
        ['Investment Grade Bonds', 100],
        ['High Yield Bonds', 200],
        ['Hedged Equity', 300],
        ['Global Equity', 400],
        ['Cash', 500],
        ['Cash', 500],
        ['Hedged Equity', 300],
        ['Global Equity', 400],
        ['Cash', 500],
        ['High Yield Bonds', 200],
        ['Hedged Equity', 300],
        ['Global Equity', 400],
        ['Cash', 500],
        ['High Yield Bonds', 200],
        ['Hedged Equity', 300],
        ['Global Equity', 400],
      ]
    }],
    exporting: {
      enabled: false
    },
    credits: {
      enabled: false
    }
  });

});

演示

如果要像在图像中那样放置数据标签,则必须自己放置数据标签。

一种方法是根据饼图切片值手动计算位置。 另一个,使用相同的数据创建另一个饼图系列,使其不可见并使用其数据标签。

series: [{
  enableMouseTracking: false,
  showInLegend: false,
  color: 'transparent',
  colorByPoint: false,
  size: '100%',
  innerSize: '60%',
  dataLabels: {
    style: {
      "color": "black",
      "fontSize": "11px",
      "fontWeight": "bold",
    },
    connectorWidth: 0,
    connectorPadding: 0,
    distance: -35,
    formatter: function() {
      return Math.round(this.percentage) + ' %';
    }
  },

}, {
  name: 'Asset Allocation',
  dataLabels: {
    enabled: false
  },
}]

例如: https//jsfiddle.net/3me3pyyf/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM