나는 ChartJS 꽤 새로운 그리고 난 가로 막대 차트에 봉착 : 대한ChartJS 수평 차트 디스플레이 전설
var ctx = document.getElementById("mybarChart");
ctx.height = 300;
var mybarChart = new Chart(ctx, {
type: 'horizontalBar',
responsive: true,
data: data,
options: {
legend: {
display: false
},
scales: {
yAxes: [{
display: false,
ticks: {
beginAtZero: true
},
gridLines: {
color: "rgba(0, 0, 0, 0)",
}
}],
xAxes: [{
display: false,
gridLines: {
color: "rgba(0, 0, 0, 0)",
},
barPercentage: 0.5,
categoryPercentage: 0.5
}]
}
}
});
:
HTML
<canvas id="mybarChart"></canvas>
자바 스크립트를 나는 각 막대에 과 같은 범례를 추가하려하지만 지금은 모양이 같습니다.
나는 추가하려고 시도했다.
onAnimationComplete: function() {
var ctx = this.chart.ctx;
ctx.font = this.scale.font;
ctx.fillStyle = this.scale.textColor
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
this.datasets.forEach(function (dataset) {
dataset.points.forEach(function (points) {
ctx.fillText(points.value, points.x, points.y - 10);
});
})
}
그러나 여전히 같은 결과. 내가 도대체 뭘 잘못하고있는 겁니까? 뭔가가 here인데 각 막대에 표시된 레이블은 Y 축의 눈금입니다. 각 막대에 범례를 추가하고 툴팁을 유지할 수 있습니까?
미리 감사드립니다.
툴팁을 유지하고 싶지만 막대 위에 마우스를 가져 가면 라벨이 사라져서 안됩니다. 레이블 바로 옆에 값을 추가하고 툴팁을 비활성화하려면이 작업을 수행하는 것이 좋습니다. – Dana
나는 ctx.fillText (dataset.label + '+ dataset.data [0], left + 10, model.y + 8)를 편집했습니다. 그리고 그것은 완벽하게 작동합니다 – Dana
도움을 많이 주셔서 감사합니다! :) – Dana