Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 图表Js。在X轴上固定标签的位置_Javascript_Chart.js - Fatal编程技术网

Javascript 图表Js。在X轴上固定标签的位置

Javascript 图表Js。在X轴上固定标签的位置,javascript,chart.js,Javascript,Chart.js,正如你在这张照片上看到的。x轴标签未与该标签的条对齐。我怎样才能解决这个问题?另外,我想让月份从右边开始,现在月份从左边开始,所以12月是从右边开始的第一个月,我希望它是从左边开始的第一个月 var Top5CompaniesPieChart = ({ type: 'bar', data: { datasets: newDataset, }, options: {

正如你在这张照片上看到的。x轴标签未与该标签的条对齐。我怎样才能解决这个问题?另外,我想让月份从右边开始,现在月份从左边开始,所以12月是从右边开始的第一个月,我希望它是从左边开始的第一个月

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]}]
})

请发布生成图表的代码。否则,很难想出解决您问题的解决方案。@我刚刚更新了问题,谢谢您告诉我。