Chart.js - 在 y 轴和第一列栏之间增加 space
Chart.js - Increase space between y Axes and the first column bar
我试图在第一个表示的数据条和 y 轴之间给出 space。
工作示例:
https://codesandbox.io/s/gracious-breeze-sc4zb?file=/src/App.js
预期行为:(尝试在红色所在的位置添加填充)
您可以向数据集添加空数据和字段,也可以使用填充。
额外字段:
var options = {
type: 'bar',
data: {
labels: ["", "Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [null, 12, 19, 3, 5, 2, 3],
backgroundColor: 'pink'
}]
},
options: {}
}
var 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/3.5.1/chart.js"></script>
</body>
开始填充 cros:
var options = {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'orange'
}]
},
options: {
scales: {
y: {
ticks: {
padding: 20,
crossAlign: 'start'
}
}
}
}
}
var 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/3.5.1/chart.js"></script>
</body>
我试图在第一个表示的数据条和 y 轴之间给出 space。
工作示例: https://codesandbox.io/s/gracious-breeze-sc4zb?file=/src/App.js
预期行为:(尝试在红色所在的位置添加填充)
您可以向数据集添加空数据和字段,也可以使用填充。
额外字段:
var options = {
type: 'bar',
data: {
labels: ["", "Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [null, 12, 19, 3, 5, 2, 3],
backgroundColor: 'pink'
}]
},
options: {}
}
var 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/3.5.1/chart.js"></script>
</body>
开始填充 cros:
var options = {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'orange'
}]
},
options: {
scales: {
y: {
ticks: {
padding: 20,
crossAlign: 'start'
}
}
}
}
}
var 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/3.5.1/chart.js"></script>
</body>