chart.jsの3.x 系は 2.x 系と仕様が変わっている
version 3.3.2
chart.jsのdocumentは、相変わらず設定の階層が分かりにくい。
let config = {
labels: chart_labels,
datasets: [
{
type: 'line',
label: '金額',
data: line_Data,
steppedLine: false,
borderColor: 'rgba(54, 162, 235, 1)',
fill : false,
yAxisID: "y_left" //y軸のID1
},{
type : 'bar',
label : '請求書数',
data: bar_Data,
borderColor: 'pink',
borderWidth: 2,
backgroundColor: 'rgba(252, 217, 236, 0.5)',
yAxisID: "y_right"//y軸のID2
}
],
}
let option = {
responsive: true,
plugins: {
legend : {// 凡例の非表示
display : false
}
},
scales: {
y_left:{//y軸のID1
type: "linear",
position: "left", //y軸を左側に表示
},
y_right:{//y軸のID2
type: "linear",
position: "right",//y軸を右側に表示
grid: { // gridを表示しない
drawOnChartArea: false
}
},
y: { //y軸のスケール
min: 0,
}
},
}
this.chart = new Chart(this.ctx, {
data: config,
options: option
});
npmでのchart.jsのinstall
# npm install chart.js