score:11
Accepted answer
You can achieve this using ticks callback function (for trimming the x-axis labels) and tooltips callback function (to dispaly the original text on tooltips)
var ctx = document.getElementById('c').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May'],
datasets: [{
data: [1, 2, 3, 4, 5],
backgroundColor: ['#30799f', '#ac51c3', '#4ba57b', '#e3297d', '#e35c32'],
borderColor: ['#30799f', '#ac51c3', '#4ba57b', '#e3297d', '#e35c32'],
borderWidth: 1
}]
},
options: {
responsive: false,
scales: {
xAxes: [{
ticks: {
callback: function(t) {
var maxLabelLength = 3;
if (t.length > maxLabelLength) return t.substr(0, maxLabelLength) + '...';
else return t;
}
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 1
}
}]
},
legend: {
display: false
},
tooltips: {
callbacks: {
title: function(t, d) {
return d.labels[t[0].index];
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="c" width="350" height="200"></canvas>
Source: stackoverflow.com
Related Query
- ChartJS - Set different hover-text than x-axis description
- chartjs custom y axis values, different text for each one
- How to set ChartJS Y axis title?
- Chartjs 2.7.3: Set Y data at the correct X position axis
- ChartJs line chart - display permanent icon above some data points with text on hover
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- chartjs - how to set the order in which the different charts are displayed
- Chartjs different row background colors according to Y axis values
- How to set max smaller than min in ChartJS
- ChartJS radar-chart hover text
- How to set ChartJS Axis label with PrimeFaces
- Chartjs is graphing my values at positions 0,1,2 rather than their values along the x axis
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- ChartJS set default axis
- Set different color for each bars using ChartJS in Angular 4
- How to set min Value a step down of min value received from database in Y Axis in ChartJS
- How to set subscript text in Chart.js axis title
- Chartjs Bar Chart Y Axis set base starting value to not be 0
- Chartjs axis description is not selectable and therefor not copyable
- Adding text inside 2 different Doughuts chartjs
- ChartJS set color of Line chart points depending on Y Axis
- How to set max and min value for Y axis
- In Chart.js set chart title, name of x axis and y axis?
- Different color for each bar in a bar chart; ChartJS
- ChartJS - Different color per data point
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- ChartJS: How to set fixed Y axis max and min
- how to plot multiple time series in chartjs where each time series has different times
- Chart Js change text label orientation on Ox axis
More Query from same tag
- Loading Laravel Chart consoletvs/charts:7.*
- Angular chart showing series but no data
- Display some chart.js in the popup of chrome's extensions
- Chart.js is not displayed when page loads first time
- How to convert chart.js library chart to image in pure node.js without using HTML and CSS?
- How to chart missing data in chartjs
- Chart.js Bubble chart with custome X-axis labels
- Chartjs Counting Elements in a Chart
- How to decrease the barthickness in ng2-charts?
- Construct a bar chart using chart.js
- How to expand the slice of donut chart in chartjs?
- Chart.js | Trouble refreshing line chart with "setInterval"
- how to add fill on line diagram?
- Make labels of ChartJS radar in a few rows
- How to join two objects in array
- Display ellipsis for null or empty values in the bar chart using Chart.js
- How can I replace null value with n/a in ruby on rails?
- How to get certain text from json object value
- ChartJS, nested flexbox, not shrinking
- Pass context to options on React ChartJS 2
- ChartJS using multiple Y axes
- chart.js mixed chart types
- Chartjs How to render a custom horizon line under X-Axis
- Get string[] in razor view javascript from mvc controller
- chart.js d3js chart in time scale, data from CSV file
- How to draw multiple line on y axis for same x axis in chartjs v2?
- ChartJS Line Chart - Points Connected out of order for Timeseries in Angular 6
- webpack `this` not pointing to window (Chart.js breaks)
- How To Add Center-Text in Donut Chart Js
- How can I move a label left, paint it black, or remove it (Chart.JS)?