i found this page to be helpful:

he shows where and how to define the function for your custom tooltip, as well as an example of the styling. i had to modify the code to match my needs, but this is a great example on how to implement the custom tooltip feature.

some things to note that threw me off at first:

1) the id in the style rules need to be modified to match your tooltip div. (this is obvious, but i didn't catch it at first)

2) tooltip.text will follow the format you set for 'tooltiptemplate' in your options, or the default tooltiptemplate set in chart.js


may be this can help you

   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] = label.substring(1, 4);

var data = {
labels: ["1/jan/08", "15/fab/08", "1/mar/08", "1/apr/08", "10/apr/08", "10/may/2008", "1/jun/2008"],
datasets: [{
    label: "first dataset",
    fillcolor: "rgba(220,220,220,0.2)",
    strokecolor: "rgba(220,20,20,1)",
    pointcolor: "rgba(220,20,20,1)",
    pointstrokecolor: "#fff",
    pointhighlightfill: "#fff",
    pointhighlightstroke: "rgba(220,220,220,1)",
    data: [65, 59, 80, 81, 56, 55, 90]
}, {
    label: "third dataset",
    fillcolor: "rgba(151,187,205,0.2)",
    strokecolor: "rgba(15,187,25,1)",
    pointcolor: "rgba(15,187,25,1)",
    pointstrokecolor: "#fff",
    pointhighlightfill: "#fff",
    pointhighlightstroke: "rgba(151,187,205,1)",
    data: [38, 55, 50, 65, 35, 67, 54]


var ctx = document.getelementbyid("mychart").getcontext("2d");

var mychart = new chart(ctx).linealt(data);

// chart.js replaces the base inrange function for line points with a          function that checks only the x coordinate
// we replace it with the original inrange fucntion (one that checks both x and y coordinates)

 mychart.datasets.foreach(function(dataset) {
  dataset.points.foreach(function(point) {
    point.inrange = chart.point.prototype.inrange;

// chart.js shows a multitooltip based on the index if it detects that there are more than one datasets
// we override it to show a single tooltip for the inrange element

mychart.showtooltip = function(chartelements, forceredraw) {
  // this clears out the existing canvas - the actual chart.js library code is a bit more optimized with checks for whether active points have changed, etc.
  // draw tooltip for active elements (if there is one)
  chart.helpers.each(chartelements, function(element) {
    var tooltipposition = element.tooltipposition();
    new chart.tooltip({
      x: math.round(tooltipposition.x),
      y: math.round(tooltipposition.y),
      xpadding: this.options.tooltipxpadding,
      ypadding: this.options.tooltipypadding,
      fillcolor: this.options.tooltipfillcolor,
      textcolor: this.options.tooltipfontcolor,
      fontfamily: this.options.tooltipfontfamily,
      fontstyle: this.options.tooltipfontstyle,
      fontsize: this.options.tooltipfontsize,
      caretheight: this.options.tooltipcaretsize,
      cornerradius: this.options.tooltipcornerradius,
      text: chart.helpers.template(this.options.tooltiptemplate, element),
      chart: this.chart,
      custom: this.options.customtooltips
  }, this);


it is very simple when you know where to put the option.

the answer is to add the custom option when you create the chart :

chart = new chart(ctx).bar(data, {"options goes here"} );

after you pass the data variable with the data info you can add custom options, so for example you want to change the size of the title of the tooltip and you also want to put a light grey color in the title of the tooltip you would do something like that:

    chart = new chart(ctx).bar(data, { 
      //option for title font size in pixels
      tooltiptitlefontsize: 14, 
      //option for tooltip title color
      tooltiptitlefontcolor: "#eee"

another way you can do is to create the set of options as a variable for organisation purposes and to be able to reuse it.

 // create a set of relevant options for you chart  
 var myoptions = { 
   scaleshowgridlines : false,     
   responsive : true, 
   scalefontsize: 12,
   pointdotradius : 4,
   scalefontstyle: 14,
   scalelabel: "<%= ' ' + value%> %",

//create the chart
chart = new chart(ctx).bar(data, myoptions);

i hope it is clear now



you can check for tooltip css -


    bodyfontcolor: "#000000", //#000000
    bodyfontsize: 50,
    bodyfontstyle: "bold",
    bodyfontcolor: '#ffffff',
    bodyfontfamily: "'helvetica', 'arial', sans-serif",
    footerfontsize: 50,
    callbacks: {
        label: function(tooltipitem, data) {
                var value = data.datasets[0].data[tooltipitem.index];
              if(tooltipitem.index == 0) {
                return "<?php echo $data1;?>";
            else if(tooltipitem.index == 1) {
                return "<?php echo $data2;?>";
            else if(tooltipitem.index == 2) {
                return "<?php echo $data3;?>";
            else {
                return "<?php echo $data4; ?>";


the new version of chart.js, version 2, is found here:

version 2 adds tooltip callbacks:

every tooltip callback (beforetitle, title, aftertitle, etc..) accepts a string or an array. if an array is used, it will produce multiple lines. tooltips now come with a lot more options for visual customization as well.

however, there is a fork of chart.js called chartnew.js, found here:

it adds several great enhancements to the venerable chart.js, including:

  • tooltip functions (when download/unzip, look in the samples folder and look at annotatefunction.html. when hover over any point, you can do anything.)

  • passing an array of colors to a bar chart (instead of each bar in series having the same color)

  • putting text on the chart wherever you want it

many etceteras.

note that chart.js has been greatly enhanced in version 2, but the new version is not fully backwards compatible (just changing to the v2 plugin broke my existing code) whereas chartnew.js will work with old code whilst extending capabilities.


i have used this, i've found it on stackoverflow, but i try hardly to find it again

<div id="chartjs-tooltip"></div>

var chartoptions =
    customtooltips: function ( tooltip )
        var tooltipel = $( "#chartjs-tooltip" );
        if ( !tooltip )
            tooltipel.css( {
                opacity: 0
            } );

        tooltipel.removeclass( 'above below' );
        tooltipel.addclass( tooltip.yalign );

        // split out the label and value and make your own tooltip here
        var parts = tooltip.text.split( ":" );
        var innerhtml = '<span>' + parts[0].trim() + '</span> : <span><b>' + parts[1].trim() + '</b></span>';
        tooltipel.html( innerhtml );

        tooltipel.css( {
            opacity: 1,
            left: tooltip.chart.canvas.offsetleft + tooltip.x + 'px',
            top: tooltip.chart.canvas.offsettop + tooltip.y + 'px',
            fontfamily: tooltip.fontfamily,
            fontsize: tooltip.fontsize,
            fontstyle: tooltip.fontstyle
        } );

link to where i got it: chart.js: changing tooltip template


try this:

you can make changes globally using this code: = {

    // boolean - determines whether to draw tooltips on the canvas or not
    showtooltips: true,

    // array - array of string names to attach tooltip events
    tooltipevents: ["mousemove", "touchstart", "touchmove"],

    // string - tooltip background colour
    tooltipfillcolor: "rgba(0,0,0,0.8)",

    // string - tooltip label font declaration for the scale label
    tooltipfontfamily: "'helvetica neue', 'helvetica', 'arial', sans-serif",

    // number - tooltip label font size in pixels
    tooltipfontsize: 14,

    // string - tooltip font weight style
    tooltipfontstyle: "normal",

    // string - tooltip label font colour
    tooltipfontcolor: "#fff",

    // string - tooltip title font declaration for the scale label
    tooltiptitlefontfamily: "'helvetica neue', 'helvetica', 'arial', sans-serif",

    // number - tooltip title font size in pixels
    tooltiptitlefontsize: 14,

    // string - tooltip title font weight style
    tooltiptitlefontstyle: "bold",

    // string - tooltip title font colour
    tooltiptitlefontcolor: "#fff",

    // number - pixel width of padding around tooltip text
    tooltipypadding: 6,

    // number - pixel width of padding around tooltip text
    tooltipxpadding: 6,

    // number - size of the caret on the tooltip
    tooltipcaretsize: 8,

    // number - pixel radius of the tooltip border
    tooltipcornerradius: 6,

    // number - pixel offset from point x to tooltip edge
    tooltipxoffset: 10,

    // string - template string for single tooltips
    tooltiptemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",

    // string - template string for single tooltips
    multitooltiptemplate: "<%= value %>",

    // function - will fire on animation progression.
    onanimationprogress: function(){},

    // function - will fire on animation completion.
    onanimationcomplete: function(){}

use this link for reference

Related Query

More Query from same tag