簡體   English   中英

如何增加 label 和 chart.js 中的圖表區域之間的空間

[英]How to increase space between label and chart area in chart.js

我所有的標簽都在欄的頂部。 我可以看到這個這張圖片

但我希望是這樣的,這個圖像填充不適用於 xAxes,但適用於 yAxes

    legend: {display: false},
    scales: {
      xAxes: [{
        position: 'top',
        stacked: true,
        ticks: {
          stepSize: 1,
          min: 0,
          autoSkip: false,
          fontColor: '#3f7ba2',
          fontStyle: 600,
          fontFamily: 'Italic',
        },
        gridLines: {
          color: '#dedfe7',
          tickMarkLength: 0,
        }
      }],
      yAxes: [{
        stacked: true,
        ticks: {
          min: 0,
          fontColor: '#62aae8',
          padding: 5
        },
        gridLines: {
          color: '#dedfe7' //b5cce2
        }
      }],
    }

這是僅在 chart.js 版本 2.6.0 及更低版本中存在的問題。 正如您在錯誤修復下的發行說明中看到的那樣,它說在 PR 4403 中ticks.padding選項現在適用於垂直和水平比例。

因此,要解決您的問題,您需要更新到高於或等於 2.7.0 的 chart.js 版本

 const options = { type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], borderWidth: 1 }, { label: '# of Points', data: [7, 11, 5, 8, 3, 7], borderWidth: 1 } ] }, options: { scales: { xAxes: [{ position: 'top', ticks: { padding: 100 } }], } } } const ctx = document.getElementById('chartJSContainer').getContext('2d'); new Chart(ctx, options);
 <body> <canvas id="chartJSContainer" width="600" height="400"></canvas> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.js"></script> </body>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM