score:23
Just extend the line chart and replace the xLabels you don't want after your initialization
Chart.types.Line.extend({
name: "LineAlt",
initialize: function (data) {
Chart.types.Line.prototype.initialize.apply(this, arguments);
var xLabels = this.scale.xLabels
xLabels.forEach(function (label, i) {
if (i % 2 == 1)
xLabels[i] = '';
})
}
});
var lineChartData = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
datasets: [
{
fillColor: "#79D1CF",
strokeColor: "#79D1CF",
data: [59, 80, 81, 56, 55, 40, 34, 43, 43, 12, 65, 65]
}
]
};
var ctx = document.getElementById("myChart").getContext("2d");
var myLine = new Chart(ctx).LineAlt(lineChartData);
Fiddle - http://jsfiddle.net/ttz5t3dx/
score:1
At Chart Options, under xAxes you can specify the maxTickLimit property to whatever you like:
xAxes: [{
ticks: {
autoSkip:true,
maxTicksLimit:3
}
}]
Fiddle : https://jsfiddle.net/p63z7zys/1/
score:1
This was one of the trickiest things that I deal with while using ChartJs.
I'm going to share my solution: I just played with the chart options. First I will define some properties for my xAxe. Note that I'm formatting the label using the callback:
scales: {
xAxes: [{
id: "x-", stacked: false, ticks: {
autoSkip: false, callback: (label) => { return label + "TEST" } }
}
]}
To format the tooltip title I'm going to use callbacks options for the tooltips:
tooltips: {
callbacks: {
title : (tooltipItems, data) => {
var labelIndex = tooltipItems[0].index;
var realLabel = data.labels[labelIndex];
return realLabel + "TOOLTIP";
}
}
}
Using the chart options like that, I'm able to show different content for the x-axis labels and the corresponding tooltip titles:
You can find the full sample here.
Hope this helps.
score:3
To extend on potatopeelings answer, we can do:
var xLabels = this.scale.xLabels
var modVal = Math.ceil( xLabels.length / 10)
xLabels.forEach(function (label, i)
{
if (i % modVal != 0)
xLabels[i] = '';
})
to limit the number of labels (in this case 10) so your labels will never be crowded no matter how many data points you have.
score:5
For anyone looking to achieve this on Chart JS V2 the following will work:
var options = {
scales: {
xAxes: [{
afterTickToLabelConversion: function(data){
var xLabels = data.ticks;
xLabels.forEach(function (labels, i) {
if (i % 2 == 1){
xLabels[i] = '';
}
});
}
}]
}
}
Then pass the options variable as usual into a:
myLineChart = new Chart(ctx, {
type: 'line',
data: data,
options: options
});`
Source: stackoverflow.com
Related Query
- show label in tooltip but not in x axis for chartjs line chart
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Chartjs - Donut Chart label for small values not visible
- Chart.js two y axes line chart tooltip value incorrect for 2nd y axis
- Chartjs backgroundColor for line chart does not appear in Vue app
- Show label for every data point in line chart
- Is there any way to show a tooltip for points which are not visible on the chart in Chart.js?
- Trying to call API and plot a line chart but it does not show
- Chart Js Change Label orientation on x-Axis for Line Charts
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Chart.js how to show cursor pointer for labels & legends in line chart
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- chartjs show dot point on hover over line chart
- ChartJS Line Graph - Multiple Lines, Show one Value on Tooltip
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Chart JS show multiple data points for the same label
- Show data dynamically in line chart - ChartJS
- Map event position to y axis value in chartjs line chart
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- PrimeNg bar chart how to show a label for the y-axis
- Chart.js line chart tooltip shows wrong label when line doesn't start at first label
- Add a text as tooltip for each point on a line chart
- chartjs - multi axis line chart - cannot read property 'min' of undefined
- Chart.js tooltip not showing on line chart
- annotation line not visible in scatter chart in chartjs
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- How to draw multiple line on y axis for same x axis in chartjs v2?
- ChartJS shows date, but not time, when displaying labels in time axis
More Query from same tag
- Chartjs! How to remove datalabel when value is 0
- How to add a horizontal line at a specific point in chart.js when hovering?
- Horizontal line syncing across multiple charts when hovering with Chart.js in Typescript-react
- Angularjs - Can't call the value from form to graph
- how can I render multiple charts in chartjs?
- Pushing API Data into Chart.js
- Two Y-axis not aligning correctly
- Chartjs not rendering in navigation stack
- how to populate my chartjs piechart dynamically
- Creating a Reusable Chartjs Function
- Chart.js stacked and grouped horizontalBar chart
- Edit styles for axes in ChartJS bar chart, when gridlines are hidden
- How to remove transparency from bar charts?
- ChartJS set styling on the last point only
- chart.js how do we extract clicked var?
- Cannot import chart.js-plugins-annotations
- ChartJS using AJAX call to retrieve data isn't rendering visualization
- Using ChartJs with MVC 5 Razor
- Chart.js show negative value in the top half
- Chart.js canvas : can't center it
- Chart.js scatter plot fill portions of chart based on value
- Laravel Chart JS change data with dropdown
- Chart doesn't display fonts
- Moving vertical line when hovering over the chart using chart.js in v2.9.4
- Date range picker and chart js
- Angular chart from Chart.js
- How to add Canvas tag inside repeater
- Chart.js set global point size not working
- how I can get label name when user click on particular area in doughnut chart.js? I am not able to find the index of selected area for chart.js
- Control Scaling of Canvas When dragged out of chart limit