highcharts - 在一个容器中使用多个饼图时如何对齐高图图例?
问题描述
嗨,我使用 HighCharts 在一个容器中有两个饼图。
Highcharts.chart('container', {
chart: {
type: 'pie'
},
plotOptions: {
series: {
dataLabels: {
enabled: false
}
}
},
series: [{
size: '50%',
center: ['25%', '50%'],
data: [1, 2, 3, 4, 5, 6],
showInLegend: true,
}, {
size: '50%',
center: ['75%', '50%'],
data: [1, 2, 3, 4, 5, 6],
showInLegend: true,
}]
});
现在我想对齐每个饼图图例,以便用户可以区分哪个图例属于哪个饼图。
如何解决这个问题?
谢谢
解决方案
目前,这是不可能的。图表上只能有一个图例。
作为一种解决方法,您可以将它们拆分为单独的容器:
Highcharts.chart('container1', {
chart: {
type: 'pie'
},
title: {
text: ''
},
plotOptions: {
series: {
dataLabels: {
enabled: false
}
}
},
credits: {
enabled: false
},
series: [{
size: '80%',
data: [1, 2, 3, 4, 5, 6],
showInLegend: true,
}]
});
Highcharts.chart('container2', {
chart: {
type: 'pie'
},
title: {
text: ''
},
plotOptions: {
series: {
dataLabels: {
enabled: false
}
}
},
credits: {
enabled: false
},
series: [{
size: '80%',
data: [1, 2, 3, 4, 5, 6],
showInLegend: true,
}]
});
#container1 {
width: 50%;
float: left;
}
#container2 {
width: 50%;
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container1"></div>
<div id="container2"></div>
演示:
推荐阅读
- angular - 从地图角度获取属性
- python - 导入和独立函数
- google-apps-script - 谷歌工作表没有将行复制到正确的工作表
- node.js - React + Express google Oauth 错误 - CORS 策略:请求的资源上不存在“Access-Control-Allow-Origin”标头
- python - 在为斐波那契数列编写代码时,我面临的问题是索引错误
- reactjs - 通过单击主页按钮,我想显示一个组件,通过单击购物车按钮,我想显示另一个组件(使用布尔值)
- javascript - 如何在包含具有数组值的子对象的对象中搜索值
- flutter - 为什么使用这个简单的 initState 代码会导致 Flutter 崩溃?
- vba - InternetExplorer html attribute change
- python - 为什么不能从python中的主类导入子类