I want to pass this json response data to a chartjs horizontal bar using angular this is the response :
Response: [
{
Description: "Prima Fase"
Id: 49
Items: [
{Id: -1, Description: "Nessun Canale", Number: 7},
{Id: 5, Description: "Altro Canale", Number: 3},
{Id: 21, Description: "Collaboratore Enzo", Number: 1}
},
{
Description: "Seconda Fase"
Id: 70
Items: [
{Id: -1, Description: "Nessun Canale", Number: 3},
{Id: 3, Description: "Web", Number: 3},
{Id: 5, Description: "Altro Canale", Number: 3},
{Id: 27, Description: "15C", Number: 1},
]
}
]
I tried this using x axes and z axes of the horizontal bar of chart js using this code
getDataForFunnel() {
this.barChartData = [];
this.barChartLabels = [];
this.funnelService.getFunnelGraph(this.funnelForm.value).subscribe(
(response) => {
this.currentResponseItems = response.Response.Items || [];
this.funnelService.allDatasFunnel = response.Response.Items || [];
this.currentResponseMessage = response.Response.Message;
if (this.currentResponseItems) {
this.currentResponseItems.forEach((y) =>
this.barChartLabels.push(y.Description)
);
let array = [];
this.currentResponseItems.forEach((x) => {
array.push(x.Id);
})
this.currentResponseItems.forEach((x) => {
x.Items.forEach((z) => {
// console.log(z.Id)
z["phaseId"] = x.Id;
let zData = [];
let number = array.indexOf(z.phaseId);
if (z.Number != 0) {
zData[number] = z.Number;
this.barChartData.push({
data: zData,
stack: "a",
label: z.Description,
idStatoAffiliazione: x.Id,
channelID: z.Id,
});
}
})
});
But it seems it doesont work because i alwyas have duplication with different colors like this: i want to regroupe each canal with diffrent phases in order to eliminate duplications in the chart and give them the same color in each phase enter image description here