Padding Between Pie Charts in chart js(图表js中饼图之间的填充)
问题描述
我正在使用 chart.js 进行项目,我需要知道是否有办法在饼图的数据集之间添加一些空间.
I am working on a project using chart.js for work and I need to know if there is a way to add some space between datasets of a pie chart.
到目前为止,我在下面的图表中看到了,我希望内部和外部数据集之间有一些填充.
What I have so far is in the chart depicted below, and I want there to be some padding between the inner and outer datasets.
我尝试将其中一个图表设置为 doughnut 类型或在内部图表上添加更厚的外边框,但这些都不是我需要的.
I have tried setting one of the charts to a doughnut type or adding a thicker outer border on the inner chart, and neither of those are what I needed.
推荐答案
您可以通过在两个现有数据集之间添加一个空数据集并定义一个 weight
空数据集和内部数据集的属性.
You can obtain the desired result by adding an empty dataset between the two existing ones and defining a weight
property on the empty and the inner dataset.
const colors = ["#FF6384", "#36A2EB", "#FFCE56"];
var pieChart = new Chart("myChart", {
type: 'pie',
data: {
labels: ["Red", "Blue", "Yellow"],
datasets: [{
data: [8, 5, 6],
backgroundColor: colors,
},
{
weight: 0.2
},
{
data: [5, 7, 4],
backgroundColor: colors,
weight: 1.2
}]
}
})
<script src="aHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvQ2hhcnQuanMvMi45LjMvQ2hhcnQubWluLmpz"></script>
<canvas id="myChart"></canvas>
这篇关于图表js中饼图之间的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:图表js中饼图之间的填充


- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01