score:7
Accepted answer
Unfortunately, with the current Chart.js API, there is no clean way to configure gridline placement independent from tick placement. In other words you cannot configure an axis to show a tick every 5 steps while still showing gridlines every 1 step.
Even though there is no clean way, there is however, still a way to get the behavior your after.
The below configuration will give you the desired results, but the only drawback is the gridlines still extend beyond the axis for the hidden tick labels (e.g. it looks a little funny).
var chartInstance = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
stepSize: 1
},
callback: function(value, index, values) {
if (value % 5 === 0) {
return value;
} else {
return ' ';
}
},
}]
}
}
});
Here is a working example via codepen.
Source: stackoverflow.com
Related Query
- Different gridline steps on chart js line chart
- Chart.js Mixed Bar and Line chart with different scales
- chart.js Line chart with different background colors for each section
- ChartJS - Line Chart with different size datasets
- Set minimum number of steps in line chart
- Add different labels in a line chart - Chart.js
- Angular-Chart-JS - Line chart with different fill colors according to points' range
- 2 Line Chart with different labels | Chart.js
- Chart.js multi line chart that has different labels
- Different labels needed for second line graph, chart js
- Limit labels number on Chart.js line chart
- Chart.js - How to set a line chart dataset as disabled on load
- Chart Js Change Label orientation on x-Axis for Line Charts
- Draw horizontal line on chart in chart.js on v2
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Remove the vertical line in the chart js line chart
- Moving vertical line when hovering over the chart using chart.js
- create a multi line chart using Chart.js
- How to add an on click event to my Line chart using Chart.js
- line chart with {x, y} point data displays only 2 values
- Chart.js how to show cursor pointer for labels & legends in line chart
- Line chart disable interpolation
- Chart.js line chart set background color
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js line chart is cut off at the top?
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- How to display Line Chart dataset point labels with Chart.js?
- show label in tooltip but not in x axis for chartjs line chart
- chartjs show dot point on hover over line chart
More Query from same tag
- Javascript Chart: How to hide the data
- TopoJson and ChartGeo/ChartJS: Unexpected geomerty
- Css style not working well when resizing chart height in angular application
- How to create a stacked donut chart in Angular 5
- Chart Js function (Chart.js) is stuck in a loop
- How to populate a charts.js pie chart using json array
- Chart.js Doughnut with rounded edges and text centered
- Chart.js Passing an array starting with 1 instead of 0 problem
- Format chart.js x-axis labels to specific timezone
- Labels for Nested Doughtnut Chart React ChartJS
- how to label axis within radar chart with chart.js
- (Chart.js 3.7.0) change position of x-axis ticks to alternate between each tick?
- Remove radar chart labels in chart.js
- How to make a child component of a sibling component refresh when a button is pressed in ReactJS?
- How can I format chart.js data labels while using chart.js datalabels plugin?
- Some imports are missing in ng2-charts@3.0.8
- Horizontal Bar-Chart - angular-chart.js
- How can I delete an instance of a chart using chart.js
- Chart.js Timeseries chart - formatting and missing data values
- Add HTML to label of bar chart - chart js
- Graph streaming real-time data with react and chartjs
- Django Time Series with Chart JS
- Angular-chart.js - Make line chart does not curve
- Chart.js v3.60 - Add % symbol to the end of the tooltip label on a doughnut chart?
- Unable to hide x axis for horizontal bar chart vue js
- yAxis labels are being cut off in ngEchars (Echarts)
- chart.js working fine on my localhost but it is not working online
- PHP/Laravel - Chartjs implode does not function
- Chart js - set width to a specific bar
- Angular and ChartJS to create bar chart