【问题标题】:Highcharts pie dropdown showing labels inside the pieHighcharts 饼图下拉菜单显示饼图内的标签
【发布时间】:2018-03-28 06:37:03
【问题描述】:

我想通过向下钻取在饼图中显示 2 个数据标签。我知道这可以通过用不同的数据标签覆盖 2 个饼图来实现。但是,在向下钻取中,它只显示 1 个数据标签,这是我放置的最后一个(第一个数据标签被 highcharts 忽略)。

这是我的尝试: https://jsfiddle.net/firstlutfi/a3v3mhef/

    $('#chart').highcharts({
    chart: {
        type: 'pie'
    },
    xAxis: {
        type: 'category'
    },
    tooltip: {
        headerFormat: '<span style="font-size:10px">{series.name}</span><br>',
        pointFormat: '{point.name}: <b>{point.percentage:.2f}%</b>',
            percentageDecimals: 0
    },
            plotOptions: {
        pie: {
            size: '80%',
            cursor: 'pointer',
        data: [{
            name: 'Jakarta',
            y: 7000000,
            drilldown: 'jakarta_sales'
        }, {
            name: 'New York',
            y: 5000000,
        },
        ]
        },
    },
    series: [{
                    type: 'pie',
        name: 'Sales Details',
        colorByPoint: true,
                    dataLabels: {
            verticalAlign: 'top',
            enabled: true,
            color: '#000000',
            connectorWidth: 1,
            distance: -30,
            connectorColor: '#000000',
            format: '{point.percentage:.2f}%'
        },
    },{
                    type: 'pie',
        name: 'Sales Details',
        colorByPoint: true,
                    dataLabels: {
            verticalAlign: 'top',
            enabled: true,
            color: '#000000',
            connectorWidth: 1,
            distance: 30,
            connectorColor: '#000000',
            formatter: function () {
                return '<b>' + this.point.name + '</b>:<br/> ' + this.y + ' ';
            }
        }
    }],
    exporting: {
      enabled: true,
    },
    drilldown: {
        series: [
                    {
            name: 'Jakarta Sales',
            id: 'jakarta_sales',
            data: [
                {name:'Car Brand A', 
                dataLabels: {
                  verticalAlign: 'top',
                  enabled: true,
                  color: '#000000',
                  connectorWidth: 1,
                  distance: -30,
                  connectorColor: '#000000',
                  format:'{point.percentage:.2f}%'
                },
                y:800000},
                                    {name:'Car Brand B', y:400000},
            ]
        },
        {
            name: 'Jakarta Sales',
            id: 'jakarta_sales',
            data: [
                {name:'Car Brand A', 
                dataLabels: {
                  verticalAlign: 'top',
                  enabled: true,
                  color: '#000000',
                  connectorWidth: 1,
                  distance: 30,
                  connectorColor: '#000000',
                  format:'{point.name}:<br/> {point.y}'
                },
                y:800000},
                                    {name:'Car Brand B', y:400000},
            ]
        },]
    }
});

更新:

点击 jakarta 数据,你会得到这个

我想要的结果是在钻取中有 2 个标签。一个是数量(在馅饼的外面)和百分比(在馅饼里面)。

有谁知道如何在每个图表(包括向下钻取)中使用 2 个数据标签(内部和外部)? 谢谢。

【问题讨论】:

  • 查看这个演示jsfiddle.net/zzo5zhfe,问题解决了
  • 什么是2个数据标签(内部和外部)你能解释一下
  • @Deep3015 我用图片更新了我的问题,所以你可以看到差异
  • 看来 我知道这可以通过用不同的数据标签覆盖 2 个饼图来实现。 不像你说的那样在向下钻取中工作

标签: javascript highcharts pie-chart


【解决方案1】:

我看到您使用解决方法通过使用两个饼图来呈现每个点的多个标签。该解决方案的问题是......您无法从一个饼图向下钻取到多个饼图(ID 是唯一的)。

提醒:还有另一种解决方法:Highcharts. Pie chart. DataLabels formatter

在您的情况下,请尝试 async-drilldown(请参阅drilldown event 中的详细信息):

https://jsfiddle.net/BlackLabel/a3v3mhef/77/

片段:

  • 创建事件:

    chart: {
      type: 'pie',
      events: {
        drilldown: function (e) {
          this.addSingleSeriesAsDrilldown(e.point, drilldownSeries[0]);
          this.addSingleSeriesAsDrilldown(e.point, drilldownSeries[1]);
    
          this.applyDrilldown();
        }
      }
    },
    
  • 在一个点上启用向下钻取:

    data: [{
      name: 'Jakarta',
      y: 7000000,
      drilldown: true // just enabled, no ID
    }, {
      name: 'New York',
      y: 5000000,
    }]
    
  • 设置系列参考:

    var drilldownSeries = [{ ... }, { ... }];
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多