[英]how to display bars in chartjs
I create a chart using chartjs, how do I display the pediactric to be visible horizontally bar?我使用chartjs创建了一个图表,如何将儿科显示为水平条形?
<canvas id="myChart"></canvas>
</div>
<script>
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: ["Interna", "Pediatric", "Obygn", "Surgical"],
datasets: [{
label: '100% of Votes',
data: [80, 55, 60, 70],
backgroundColor: [
'rgba(150, 99, 132, 0.6)',
'rgba(180, 99, 132, 0.6)',
'rgba(210, 99, 132, 0.6)',
'rgba(240, 99, 132, 0.6)'
],
borderColor: [
'rgba(150, 99, 132, 1)',
'rgba(180, 99, 132, 1)',
'rgba(210, 99, 132, 1)',
'rgba(240, 99, 132, 1)'
],
borderWidth: 2,
hoverBorderWidth: 0
}]
},
options: {
The x-axis scale begins at 55. Since the value of Pediatric
is 55 no bar is visible. x 轴刻度从 55 开始。由于Pediatric
的值为 55,因此看不到任何条形。
Set the following option to have the scale always begin at zero:设置以下选项以使比例始终从零开始:
options: {
scales: {
xAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.