Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing tooltip color in Chart.js

trying to customized the tooltip based on the value of the data. Also there are these small circular connectors or joins on the corner of a line chart, when the line goes up or down, that I am also trying to change its color and for those I don't even know where to start. Here is a portion of the code I am using where I am trying to return and change the tooltip color using Chart.js

        tooltips: {
          mode: 'index',
          intersect: false,
          callbacks: {

            label: function(tooltipItem, data) {
              if (tooltipItem.yLabel === 1) {

    //return 'Normal';
            return { 'Normal',
             tooltipFillColor: 'rgb(255, 99, 132)', // red
        };

              } else if (tooltipItem.yLabel === 2) {

               // return 'Active';
        return { 'Acitve',
             tooltipFillColor: 'rgb(75, 192, 192)', // green
        };

              }
            }
          }
        },

Thanks for all the help!

like image 454
Maresia Avatar asked Mar 05 '26 12:03

Maresia


1 Answers

Alternatively, you can use the label Color function.

tooltips: {
     callbacks: {
       labelColor: function(tooltipItem,data) {
           if (tooltipItem.datasetIndex === 0) {
                return {
                    borderColor: "#FFFFFF",
                    backgroundColor: "#FFCD2E"
                        };
                 }
like image 160
Shobhit Goel Avatar answered Mar 08 '26 02:03

Shobhit Goel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!