Javascript 图表Js。在X轴上固定标签的位置
正如你在这张照片上看到的。x轴标签未与该标签的条对齐。我怎样才能解决这个问题?另外,我想让月份从右边开始,现在月份从左边开始,所以12月是从右边开始的第一个月,我希望它是从左边开始的第一个月Javascript 图表Js。在X轴上固定标签的位置,javascript,chart.js,Javascript,Chart.js,正如你在这张照片上看到的。x轴标签未与该标签的条对齐。我怎样才能解决这个问题?另外,我想让月份从右边开始,现在月份从左边开始,所以12月是从右边开始的第一个月,我希望它是从左边开始的第一个月 var Top5CompaniesPieChart = ({ type: 'bar', data: { datasets: newDataset, }, options: {
var Top5CompaniesPieChart = ({
type: 'bar',
data: {
datasets: newDataset,
},
options: {
legend: false,
responsive: true,
scales: {
yAxes: [{
position: 'right',
ticks: {
beginAtZero: true,
minHeight: -2
},
}],
xAxes: [{
offset: true,
type: 'time',
time: {
parser: 'MMM',
unit: 'month',
displayFormats: {
month: 'MMM'
}
},
gridLines: {
offsetGridLines : true
},
ticks: {
callback: function (label, index, labels) {
return translate_this_month(label);
}
}
}],
},
hover: {
mode: 'nearest',
intersect: true
},
tooltips: {
callbacks: {
title: function (tooltipItem, data) {
return translate_this_month(tooltipItem[0].label);
}
}
}
}
});
newDataset
变量通过for循环添加:
newDataset.push({
label: companiesList[month][company][0],
backgroundColor: colors[colorIterator],
data: [{x: MONTHS[parseInt(month) - 1], y: companiesList[month][company][1]}]
})
请发布生成图表的代码。否则,很难想出解决您问题的解决方案。@我刚刚更新了问题,谢谢您告诉我。