【发布时间】: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},
]
},]
}
});
我想要的结果是在钻取中有 2 个标签。一个是数量(在馅饼的外面)和百分比(在馅饼里面)。
有谁知道如何在每个图表(包括向下钻取)中使用 2 个数据标签(内部和外部)? 谢谢。
【问题讨论】:
-
查看这个演示jsfiddle.net/zzo5zhfe,问题解决了
-
什么是2个数据标签(内部和外部)你能解释一下
-
@Deep3015 我用图片更新了我的问题,所以你可以看到差异
-
看来 我知道这可以通过用不同的数据标签覆盖 2 个饼图来实现。 不像你说的那样在向下钻取中工作
标签: javascript highcharts pie-chart