У меня есть горизонтальный график chart.js, который выглядит следующим образом. моя гистограмма
Я ищу способ изменить метки слева "Boozman John, EldridgeКоннер и т. Д.основанный на значениях в списке, которые я получаю от вызова ajax.
Я пробовал что-то вроде
labels {
fontColor: labelcolors
},
с циклом for, чтобы получить цвета в списке "labelcolors", но не сделалне работает.
А вот мой код
`var ctx = document.getElementById("GeneralChart");
var GeneralChart = new Chart(ctx, {
type: "horizontalBar",
data: {
labels: gen_candidate,
datasets: [
{
label: "Committee expenditure",
backgroundColor: "orange",
borderColor: "yellow",
borderWidth: 1,
xAxisID: "expenditure",
data: gen_expenditure
},
{
label: "General votes",
backgroundColor: "green",
borderColor: "green",
borderWidth: 1,
xAxisID: "votes",
data: general_votes
},
]
},
options: {
responsive: true,
legend: {
position: "top"
},
title: {
display: true,
text: "Money and Votes for General Election "+ state
},
scales: {
yAxes: [{
position:"left",
id: "y-axis",
ticks: {
autoSkip: false,
}
}],
xAxes: [{
type: 'linear', //type: 'linear', is needed for horizontal vote
position: "top",
id: "expenditure",
}, {
type: 'linear',
position: "bottom",
id: "votes",
ticks: {
beginAtZero: true
}
}]
}
}
});`
Есть идеи?