score:20

Accepted answer

first, you would better edit your chart properties directly from the options of the chart, and not in the scale service as you did so that it won't affect every chart on your page (if you have several).

to achieve what you already did, add the function you used in your options :

options: {
    scales: {
        xaxes: [{
            ticks: {
                callback: function(tick) {
                    var characterlimit = 20;
                    if (tick.length >= characterlimit) {
                        return tick.slice(0, tick.length).substring(0, characterlimit - 1).trim() + '...';
                    }
                    return tick;
                }
            }
        }]
    },
}

it is basically an edit of what is displayed as labels on your xaxe.


however, we still have the same problem : both the labels and the tooltips display the trimmed string.

to fix it, you'll also need to edit the callback of the tooltip :

options: {
    // other options here, `scales` for instance
    // ...
    tooltips: {
        callbacks: {

            // we'll edit the `title` string
            title: function(tooltipitem){
                // `tooltipitem` is an object containing properties such as
                // the dataset and the index of the current item

                // here, `this` is the char instance

                // the following returns the full string
                return this._data.labels[tooltipitem[0].index];
            }
        }
    }
}


you can see a full example in this jsfiddle and here is its result :

enter image description here


Related Query

More Query from same tag