How to Change Chartjs Tooltip Font Sizes

Chart js tooltip is in the options/plugins namespace. We can change font size in the titleFont or bodyFont object under the options/plugins namespace. 

The below example is a bar chart with tooltip titleFont set to 30 nd bodyFont set to 40.

Example

Sample code

 const myChart = new Chart(ctx, {
          type: 'bar',
          data: {
              labels: [1,2,3,4,5],
              datasets: [{
                  label: 'Daily Tracking Errors',
                  data: [12, 19, 3, 5, 2, 3],
                  backgroundColor: ['rgba(54, 162, 235, 0.2)'],
                  borderColor: ['rgba(54, 162, 235, 1)'],
                  borderWidth: 1
              }]
          },
          options: {
              scales: {
                  y: {
                      beginAtZero: true,
                       ticks: {
                  		  callback: function(value, index, values) {
                    	    return  + value + '%';
                   			   },
                          font:{size:20}
                 		 }
                   
              }
          }, 
        plugins: {
            legend: {
                labels: {
                    // This more specific font property overrides the global property
                    font: {
                        size: 22
                    }
                }
            },
            tooltip:{
            titleFont:{size:30},
            bodyFont:{size:40}
          }
        }
    }
      });

Comments

Popular posts from this blog

How to Make A Reusable Image Slideshow HTML Component With Vanilla JavaScript

HTML Tags and Inline CSS that Work In Plotly.js Title

How to Type Spaces In HTML Input And Display In the Browser