Closed
Description
Hi @hcpchris,
From the donut-charts.ipynb demos:
from highcharts_core.chart import Chart
from highcharts_core.options import HighchartsOptions
options_as_str = """{
chart: {
plotBackgroundColor: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Browser<br>shares<br>January<br>2022',
align: 'center',
verticalAlign: 'middle',
y: 100
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
dataLabels: {
enabled: true,
distance: -100,
style: {
fontWeight: 'bold',
color: 'white'
}
},
center: ['50%', '75%']
}
},
series: [{
type: 'pie',
name: 'Browser share',
innerSize: '50%',
data: [
['Chrome', 73.86],
['Edge', 11.97],
['Firefox', 5.52],
['Safari', 2.98],
['Internet Explorer', 1.90],
{
name: 'Other',
y: 3.77,
dataLabels: {
enabled: false
}
}
]
}]
}"""
options = HighchartsOptions.from_js_literal(options_as_str)
donut_chart = Chart.from_options(options)
donut_chart.display()
The distance
keyword for the dataLabels has no effect, whatever the value.
Running:
donut_chart.to_json()
Return:
{
"userOptions": {
"accessibility": {"point": {"valueSuffix": "%"}},
"chart": {
"plotBackgroundColor": null,
"plotBorderWidth": 0,
"plotShadow": false,
},
"plotOptions": {
"pie": {
"center": ["50%", "75%"],
"dataLabels": {
"enabled": true,
"style": {"fontWeight": "bold", "color": "white"},
},
"type": "pie",
}
},
"series": [
{
"data": [
{"y": 73.86, "name": "Chrome"},
{"y": 11.97, "name": "Edge"},
{"y": 5.52, "name": "Firefox"},
{"y": 2.98, "name": "Safari"},
{"y": 1.9, "name": "Internet Explorer"},
{"y": 3.77, "dataLabels": {"enabled": false}, "name": "Other"},
],
"name": "Browser share",
"innerSize": "50%",
"type": "pie",
}
],
"title": {
"align": "center",
"text": "Browser<br>shares<br>January<br>2022",
"verticalAlign": "middle",
"y": 100,
},
"tooltip": {"pointFormat": "{series.name}: <b>{point.percentage:.1f}%</b>"},
}
}
Where the distance
keyword is not present.
If I look at the data_labels class, I can't see no distance
keyword.
But the JS class seems to have it: https://api.highcharts.com/highcharts/series.pie.dataLabels.distance
Trying to run this JS demo for the pie chart
options_as_str = """{
chart: {
type: 'pie'
},
title: {
text: 'Egg Yolk Composition'
},
tooltip: {
valueSuffix: '%'
},
subtitle: {
text:
'Source:<a href="https://www.mdpi.com/2072-6643/11/3/684/htm" target="_default">MDPI</a>'
},
plotOptions: {
series: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: [{
enabled: true,
distance: 20
}, {
enabled: true,
distance: -40,
format: '{point.percentage:.1f}%',
style: {
fontSize: '1.2em',
textOutline: 'none',
opacity: 0.7
},
filter: {
operator: '>',
property: 'percentage',
value: 10
}
}]
}
},
series: [
{
name: 'Percentage',
colorByPoint: true,
data: [
{
name: 'Water',
y: 55.02
},
{
name: 'Fat',
sliced: true,
selected: true,
y: 26.71
},
{
name: 'Carbohydrates',
y: 1.09
},
{
name: 'Protein',
y: 15.5
},
{
name: 'Ash',
y: 1.68
}
]
}
]
}"""
options = HighchartsOptions.from_js_literal(options_as_str)
donut_chart = Chart.from_options(options)
donut_chart.display()
Result in all labels overlapping because of the distance
keyword missing: