【问题标题】:Highcharts Pie Chart dataLabel Options Don't Work With Object InitializationHighcharts 饼图 dataLabel 选项不适用于对象初始化
【发布时间】:2015-12-26 06:08:41
【问题描述】:

这是一个 jsfiddle 示例,在该示例中,通过在创建图表对象时传递选项来初始化图表时,我无法获取要显示的数据标签值或百分比。标签中仅显示 point.name。似乎只有在运行时使用 plotOptions 结构创建整个对象时才能使这些选项起作用。

http://jsfiddle.net/nstvx7wc/7/

$(document).ready(function(){
var options = {

    chart: {
        renderTo: 'chartdiv',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },

   pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
        enabled: true,
        format: '{point.name} {point.percentage:.1f} %',
        style: {
               color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
               }
        },
    },
    title: {
           text: ''
           },
};
options.series = [{"colorByPoint": "true", "data": [{"y": 0.36, "name": "series1"}, {"y": 0, "name": "series2"}, {"y": 0, "name": "series3"}, {"y": 0.03, "name": "series4"}, {"y": 0.04, "name": "series5"}, {"y": 0.07, "name": "series6"}]}];
options.title.text = "test pie"; 
options.pie.dataLabels.enabled = 'true';
chartObject = new Highcharts.Chart(options);
});

【问题讨论】:

    标签: pie-chart


    【解决方案1】:

    您的“派”选项配置错误。 options.pie 不存在。它应该放在 series 或 plotoptions 属性下;

    看这个例子; http://jsfiddle.net/nstvx7wc/21/

    $(document).ready(function() {
      var options = {
    
        chart: {
          plotBackgroundColor: null,
          plotBorderWidth: null,
          plotShadow: false,
          type: 'pie'
        },
        title: {
          text: 'test pie'
        }
      };
    
      options.series = [{
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
          enabled: true,
          format: '{point.name} {point.percentage:.1f} %',
          style: {
            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
          }
        },
        "colorByPoint": "true",
        "data": [{
          "y": 0.36,
          "name": "series1"
        }, {
          "y": 0,
          "name": "series2"
        }, {
          "y": 0,
          "name": "series3"
        }, {
          "y": 0.03,
          "name": "series4"
        }, {
          "y": 0.04,
          "name": "series5"
        }, {
          "y": 0.07,
          "name": "series6"
        }]
      }];
    
    
      Highcharts.chart('chartdiv', options);
    });
    

    【讨论】:

      猜你喜欢
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 2019-05-28
      相关资源
      最近更新 更多