饼图非常受欢迎,用于展示一篇作品的简洁概览或比较。虽然它们比柱状图难读,但仍然是小型数据集的热门选择。
完整版(蛋黄成分饼图)
html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>蛋黄成分占比</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<style>
#container {
width: 100%;
height: 500px;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: '蛋黄营养成分占比'
},
tooltip: {
valueSuffix: '%'
},
subtitle: {
text: '数据来源:<a href="https://www.mdpi.com/2072-6643/11/3/684/htm" target="_blank">MDPI</a>'
},
plotOptions: {
pie: {
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: '占比',
colorByPoint: true,
data: [
{
name: '水分',
y: 55.02
},
{
name: '脂肪',
sliced: true,
selected: true,
y: 26.71
},
{
name: '碳水化合物',
y: 1.09
},
{
name: '蛋白质',
y: 15.5
},
{
name: '矿物质',
y: 1.68
}
]
}
]
});
</script>
</body>
</html>
图表功能
- 可点击扇区分离
- 自动显示百分比
- 鼠标悬浮显示详情
- 美观双层标签
- 100% 中文显示