Replies: 2 comments 3 replies
-
You can add a second x axis: var options = {
type: 'line',
data: {
labels: ["Jan", "Feb", "March", "Jan", "Feb", "March"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'orange'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'pink'
}
]
},
options: {
scales: {
x: {},
secondX: {
position: 'bottom',
labels: ['', 'year1', '', '', 'year2', ''],
grid: {
borderWidth: 0,
tickLength: 0
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options); |
Beta Was this translation helpful? Give feedback.
3 replies
-
@junaidtk having a second scale is probably easier as it is build in. But if a custom plugin is acceptable perhaps this might be an alternative. This is drawn within the canvas by creating a chart.js plugin. See below this will create the text as well. All you need to do is calculate the coordinates, and add padding to the bottom. For deeper understanding watch this: https://youtu.be/oVwvwl5wogI Perhaps this might be helpful. `
` |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Expected behavior
I have months in the x-axis labels and I have to groups the months into quarter/year. So how it is possible using the chart.js
Current behavior
Currently i have checked the link.
#2138
This is almost 6 year old answer, is there any easy way of implementation ? Here, it is adding the group by custom breaking of label string.
Reproducible sample
chart.min.js and Jquery
Optional extra steps/info to reproduce
No response
Possible solution
No response
Context
No response
chart.js version
v3.7.1
Browser name and version
No response
Link to your project
No response
Beta Was this translation helpful? Give feedback.
All reactions