1
私は、このような棒グラフがありますを、私はこのように、方法にして、サーバーからラベルを受け取ることができます。barChartにchart.jsを使って配列を追加するには?
"dateLabels": [
"01 Thu", "02 Fri", "03 Sat", ....
]
またはこのような:
"dateLabels": {
"dayOfMonth": [1, 2, 3, 4, ...],
"dayOfWeek": ["Th", "Fr", "Sa", "Su", ...]
}
そして、私は第一の変形を受けた場合、次に示されています1行のバーに、私はこのようにそれらを表示する必要があります。
ホー私はこれらの小鈴を別の下に表示できますか?
さらに興味があります:各バーに値を追加する方法は?
私のコードのようになります。
getCombData() {
this.XTimeApi.combData()
.subscribe((response) => {
this.data = response;
let canvas: any = document.getElementById("comb");
let ctx = canvas.getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: response.data.dateLabels, // ['01 Mon', '02 Tue', '03 Wed']
datasets:
[
{
label: "Diff",
backgroundColor: 'rgba(255, 255, 255, 0.8)',
borderColor: 'rgb(194, 194, 194)',
borderWidth: 1,
data: [0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,8,0,0,8,8,8,7,8,0,0,8],
},
{
label: "Weekend",
backgroundColor: 'rgba(194, 194, 194, 0.4)',
borderColor: 'rgb(194, 194, 194)',
borderWidth: 1,
data: [8, 8, 0,0,0,0,0,8,8,0,0,0,0,0,8,8,0,0,0,0,0,8,8,0,0,0,0,0,8,8,0],
},
{
label: "NPA",
backgroundColor: 'rgb(28, 132, 198)',
borderColor: 'rgb(28, 132, 198)',
borderWidth: 1,
data: [0, 0, 3, 0, 0, 0, 0, 0, 0,0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0]
},
{
label: "Loged hours",
backgroundColor: 'rgb(26, 179, 148)',
borderColor: 'rgb(26, 179, 148)',
borderWidth: 1,
data: [0, 0, 5, 8, 8, 7, 7, 0, 0,0, 3, 8, 8, 8, 0, 0, 9, 0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0]
},
{
label: "Overtimes",
backgroundColor: 'rgb(252, 223, 5)',
borderColor: 'rgb(194, 194, 194)',
borderWidth: 1,
data: [0, 0, 0,0,0,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
},
{
label: "No report",
backgroundColor: 'rgb(255, 255, 255)',
borderColor: 'rgb(237, 85, 101)',
borderWidth: 1,
data: [0, 0, 0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
},
{
label: "Report not send",
backgroundColor: 'rgb(237, 85, 101)',
borderColor: 'rgb(237, 85, 101)',
borderWidth: 1,
data: [0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0],
}
]
},
options: {
scaleShowLabels: true,
tooltips: {
mode: 'label'
},
legend: {
display: false
},
scales: {
scaleLabel: {
labelString: 'Text'
},
yAxes: [{
ticks: {
maxRotation: 5,
max: 10,
min: 0,
stepSize: 4
},
stacked: true
}],
xAxes: [{
ticks: {
fontSize: 10,
},
stacked: true,
gridLines: {
display: false,
}
}]
}
}
});
});
}