score:14
Accepted answer
Replace your tick's userCallback
function with the following ...
userCallback: function(item, index) {
if (!(index % 4)) return item;
}
Basically, you don't need to return any empty string for the label that you wish to hide. If you do not return anything (for the label you don't want), it won't draw any tick (as well as gridline) for that label.
ᴅᴇᴍᴏ
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept'],
datasets: [{
label: 'Standard Rating',
data: [1, 2, 3, 4, 5, 6, 7, 8, 9],
backgroundColor: 'rgba(209, 230, 245, 0.5)',
borderColor: 'rgba(56, 163, 236, 1)',
borderWidth: 1
}]
},
options: {
responsive: false,
tooltips: {
mode: 'label',
intersect: false
},
scales: {
xAxes: [{
ticks: {
userCallback: function(item, index) {
if (!(index % 4)) return item;
},
autoSkip: false
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="myChart" width="350" height="200"></canvas>
Source: stackoverflow.com
Related Query
- Show only nth tick LINE on x-axis for Chart.js diagram
- show label in tooltip but not in x axis for chartjs line chart
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- How to show tick marks and labels with grid line for the specific one on the X axis with Chart.js?
- Chart.js how to show cursor pointer for labels & legends in line chart
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- In Chart.js >3.0, on axis of type time, how to show labels and ticks only for existing data points (make labels reflect data)?
- Empty circle - only point strok in line chart for ChartJS
- Chart.js two y axes line chart tooltip value incorrect for 2nd y axis
- How do you set x and y axis and Title for a line chart using charts.js?
- ChartJS Only Show Large Font Size for a Specific Tick
- Chart JS tick options not working for y axis
- how to show only each 15th x-labels in line chart chart.js in angular 6?
- How to start Y Axis Line at 0 from right for negative values in chart js 2?
- Show label for every data point in line chart
- Line chart plotting multiple points for duplicate data on x and y axis using chart.js
- chart js how do I only show just the low/high dots on line chart?
- Using custom dataformat in chart.js for Multi Axis Line Chart
- Chart Js Change Label orientation on x-Axis for Line Charts
- line chart with {x, y} point data displays only 2 values
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js: only show labels on x-axis for data points
- chartjs show dot point on hover over line chart
- How to add second Y-axis for Bar and Line chart in Chart.js?
- chart.js Line chart with different background colors for each section
- Chart JS - set start of week for x axis time series
- How to display value of only one datapoint in line chart
- Chart looks only grey, does not show the color - Chartjs,discordjs
- Chart JS show multiple data points for the same label
More Query from same tag
- how to put a second pie chart right next to first pie chart inside the bootstrap card
- Angular and ChartJS colors
- How to change the time format displayed in the chart?
- Chart.JS removing data stuck in loop
- Chart.js 2.1.6 background color for each section
- Chart js 2.x renders the canvas invisible
- Chart.js chart onclick disables legend onclick
- How to make rectangle in chart.js
- Multiple chart on one page using chart.js and Flask app
- Chart.js - Hide line using label string after load
- Chart.js HTML custom legend issues with doughnut chart
- Show Donut / Pie Chart in bootstrap modal with legends
- How to retrieve the instance of a chart that is not global
- how to highlight bar in ChartJS with onkeyup Input
- Chart.js not showing up on online site
- Chart.js :set yAxis point to 0 when there is gap between two dates
- Chart.register is not a function
- Why is this "not defined"
- Chart.js Box Annotations Fill Entire Chart
- Two independent time axes in Chart.js
- ChartJS scatterplot multi-line tooltip, one box
- Chart JS prepend labels to x-axis with addData
- Chartjs: How to create padding between ticks and scale label
- Round pie chart in rectangular canvas
- $.function is not a function - jQuery
- Chart.js: Some sectors not showing if difference is too big
- Chart.js not resorting rows based on plugin after using update function
- ChartJS showing wrong dataset following visibility property toggle
- How to change background color of labels in line chart from chart.js?
- protoype js 1.0.6 is conflicting with chart js