首页 > 解决方案 > 如何在 Flot Char js 中居中栏

问题描述

我有,flot.js 的一些问题,在我的图表中,xaxis 不是以条为中心,我尝试使用 align: 'center' 但它不起作用,我想要的是图表正下方的 xaxis(日期标签)这是我的代码

 $.plot('#grafik-presensi', [data], {
        series: {
                bars: {
                    show: true,
                    barWidth: 0.6,
                    align:'center',
                    fill: true,
                    fillColor: {
                        colors: [{
                            opacity: 0.9
                        }, {
                            opacity: 0.9
                        }]
                    }
                }
            },
            colors: ['#25476a'],
            yaxis: {
                },
            xaxis: {
                    ticks: ticks,
                    
            },
            grid: {
                hoverable: true,
                clickable: true,
                tickColor: '#eeeeee',
                borderWidth: 0
            },
            legend: {
                show: true,
                position: 'nw'
            },
            tooltip: {
                show: true,
                content: 'Presensi %x, Jumlah %y'
            }

    });
});

在此处输入图像描述

标签: javascriptchartsbar-chartflotflotr2

解决方案


您的数据 x 值和刻度似乎根据您的时区 (GMT +7) 发生了变化。您需要确保数据和刻度都使用我们当地时间或两者都使用 UTC。请参阅此处了解更多信息。

如果无法对数据和刻度使用相同的时区,您还可以通过将 7 小时添加到它们来手动移动刻度。


推荐阅读