9👍
Updated
options: {
plugins: {
legend: {
position: "right",
align: "middle"
}
}
}
2👍
use latest version of chart.js : https://www.chartjs.org/dist/master/Chart.min.js for more reference check this documentation and add align:'middle'
in your legend it will work’s
legend: {
position: "right",
align: "middle"
},
var ctx = $('#myChart');
ctx.height(100);
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["APP1", "APP2", "APP3", "APP4", "APP5"],
datasets: [{
data: [25, 61, 47, 45, 30],
label: "Response > 5",
borderColor: "#5151A1",
backgroundColor: "#5151A1"
}, {
data: [22, 38, 53, 17, 55],
label: "Response <= 5",
borderColor: "#408040",
backgroundColor: "#408040"
}]
},
maintainAspectRatio: false,
options: {
responsive: true,
legend: {
position: "right",
align: "middle"
},
scales: {
yAxes: [{
ticks: {
min: 0,
//max: 100,
callback: function(value) {
return value + "%"
}
},
scaleLabel: {
display: true
//labelString: "Percentage"
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<canvas id="myChart" height="450" width="600"></canvas>
Check your updated fiddle here
If npm install chart.js
not working then refer this answer for more details check the chart.js documentation.
Source:stackexchange.com