javascript - 如何减少 plotly js 中标题和圆环图之间的空间?

标签 javascript charts plotly plotly.js donut-chart

我当前的代码:

const donutData = [
  {
    values: [2, 98],
    labels: ['', ''],
    sort: false,
    marker: {
      colors: ['#0099cc', '#535353'],
    },
    name: '',
    hoverinfo: 'none',
    textfont: {
      size: [16, 1],
      color: ['#ffffff', '#535353'],
      fill: ['#ffffff', '#535353'],
    },
    hole: 0.7,
    insidetextorientation: 'none',
    type: 'pie',
    textposition: 'none',
    automargin: true,
  },
];
const layout = {
  paper_bgcolor: '#262626',
  plot_bgcolor: '#262626',
  autosize: true,
  margin: { t: 100, b: 10, l: 0, r: 0 },
  font: {
    color: '#fff',
    family: 'Roboto',
    size: 18,
  },
  showlegend: false,
  width: 500,
  height: 500,
  title: {
    text: `donut`,
  },
  annotations: [
    {
      font: {
        size: 60,
      },
      showarrow: false,
      text: `30%`,
    },
  ],
};

我想减少标题和圆环图之间的空间。我尝试在 margin 对象中添加 pad:0 但它没有用。此外,我在标题对象中找不到任何相关属性。有什么属性(property)可以帮助我吗?添加了 SS。

ss

最佳答案

可以通过title参数中的变量y来控制空格,比如y=0.8如下:

title: {
    text: `donut`,
    y: 0.8  # you can change this value as you prefer to reduce the space
  },

关于javascript - 如何减少 plotly js 中标题和圆环图之间的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73878929/

相关文章:

javascript - 正确调用/获取信息

javascript - 将多级对象文字插入数组时,值困惑

javascript - 不使用 FORM 重置 INPUT

javascript - 如何在 Firefox 扩展中使用模块?

javascript - 是否可以使用plotly.js 绘制饼图?

在最近的更新之后,使用 Shinyjs 重置 event_data 似乎不再起作用

r - 使用 R 中的plot_ly 单独更改图例

c# - 使用 BackgroundWorker 更新 C# Chart

html - 如何防止内容调整 flex 元素的大小?

javascript - 使用 Google Apps 脚本的 Plotly API