I have a requirement that need to show up data in bar graph using chart.js like below,
Here, irrespective of x-axis date, the bars should be aligned in equal distance and the date format is same as in the image.
let chartStatus = Chart.getChart(this.WEIGHTS_CHART);
if (chartStatus != undefined) {
chartStatus!.destroy();
}
const weightsChart = new Chart(this.WEIGHTS_CHART, {
type: 'bar',
data: {
labels: this.objWeights.map(x => x.date),
datasets: [
{
label: "Weight",
backgroundColor: "#0072bc",
data: this.objWeights.map(x => x.weightValue)
},
{
label: "BMI",
backgroundColor: "#84b5e4",
data: this.objWeights.map(x => x.bmi)
}
]
},
options: {
responsive: true,
scales: {
x: {
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MMM DD, YYYY'
}
}
},
y: {
beginAtZero: true
}
}
}
});
}
with the above code, I'm getting output like this . Can someone help me
I want like this (https://i.stack.imgur.com/5Aiwj.png)
but with above code, I'm getting like this (https://i.stack.imgur.com/GkMGO.png)