I use Chart.js and stack groups bar chart.
The problem is that the data contains zero values and these are shown in the tooltip making it harder to read. How can I remove them?
Screenshot:
EDIT 1
This is the code that should return the options for the chart.
getChartOptions(): import('chart.js').ChartOptions | undefined {
return {
title: {
display: true,
text: 'Chart.js Bar Chart - Stacked',
},
tooltips: {
mode: 'index',
intersect: false,
},
responsive: true,
scales: {
xAxes: [
{
stacked: true,
},
],
yAxes: [
{
stacked: true,
},
],
},
};
}
EDIT 2:
ngOnInit(): void {
this.http.get("http://localhost:8080/")
.subscribe((data) => {
this.originalData = data;
this.myChart = new Chart('myChart', {
type: 'bar',
data: this.getChartData(),
options: this.getChartOptions(),
});
});
}
EDIT 3:
getChartData() {
return {
labels: this.originalData.labels,
datasets: this.originalData.datasets,
};
}
EDIT4 - Example of what getChartData() could return:
{
"labels":[
"January",
"February",
"March",
"April",
"May",
"June",
"July"
],
"datasets":[
{
"label":"Dataset 1",
"backgroundColor":"window.chartColors.red",
"stack":"Stack 0",
"data":[
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()"
]
},
{
"label":"Dataset 2",
"backgroundColor":"window.chartColors.blue",
"stack":"Stack 0",
"data":[
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()"
]
},
{
"label":"Dataset 3",
"backgroundColor":"window.chartColors.green",
"stack":"Stack 1",
"data":[
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()",
"randomScalingFactor()"
]
}
]
}