1👍
One possible way is to use chartjs-plugin-labels to add images of desired size inside individual bars.
Please have a look at the code below.
new Chart(document.getElementById('myChart'), {
type: 'bar',
data: {
labels: ['A', 'B'],
datasets: [{
label: 'My First Dataset',
data: [500, 450],
backgroundColor: ['rgba(255, 99, 132, 0.2)', 'rgba(255, 159, 64, 0.2)'],
borderColor: ['rgb(255, 99, 132)', 'rgb(255, 159, 64)'],
borderWidth: 1
}]
},
options: {
plugins: {
labels: {
render: 'image',
textMargin: -160,
images: [
null,
{
src: 'https://i.stack.imgur.com/556XZ.png',
width: 150,
height: 150
}
]
}
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
<canvas id="myChart" height="200"></canvas>
- [Chartjs]-Filter dates from the first day of the month to the current date
- [Chartjs]-ChartJS bar chart fixed width for dynamic data sets
Source:stackexchange.com