Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align Chart.JS line chart labels to the center

I'm using Chart.JS 1.0.2 to create a line chart: The chart I'm getting right now

What I'm trying to do is move the labels that are on the bottom of the chart the center of each rectangle (instead of being aligned with the vertical grid lines):

What I'm trying to get to

There is no documentation about this on chartjs.org but I believe that with a smart trick this problem can be easily solved. Any ideas on how this can be accomplished?

like image 689
DMEM Avatar asked Nov 10 '16 17:11

DMEM


2 Answers

offsetGridLines (boolean) If true, labels are shifted to be between grid lines.

type: 'line',
data: data,
options: {
    ...
    scales: {
        xAxes: [{
            gridLines: {
                offsetGridLines: true
            }
        ]}
    }
}
like image 109
user4842787 Avatar answered Nov 18 '22 10:11

user4842787


Test this:

labelOffset:-5 //adjust number
like image 1
TSupong Avatar answered Nov 18 '22 08:11

TSupong