Jorge O
Jorge O

Reputation: 51

How to change the tooltip background color in JQuery Sparklines

Is there a way to change the default background color of the tooltip in jQuery Sparklines? I have not been able to find a simple solution to this and there hasn't seem to be a similar question for sparklines tooltips. I would like to change the background color from the transparent default color to a solid grey.

I am using a custom tooltipFormatter to create the text within the tooltip, e.g.

$('#sparkline').sparkline(data, {
  type: 'bar',
  tooltipFormatter: function(sparkline, options, fields) {
     //<span>Stuff</span>
  }
});

Thanks!

Upvotes: 5

Views: 6208

Answers (3)

Mike Robertson
Mike Robertson

Reputation: 90

There are actually 2 classes that are relevant: jqstooltip, as mentioned as well as jqsfield which is most likely what you need if you want to change the text attributes.

An example:

.jqstooltip { 
 background-color: #c6e5f6 !important;
 font-size: 11px !important; 
 padding: 5px !important; 
 color: black !important; 
 overflow: auto !important; 
 text-align: center !important;  
 border-color: #CCCCCC !important; 
 max-width: 400px !important; 
 max-height: 400px !important; 
}

.jqsfield { 
 font-size: 10px !important; 
 color: black !important; /*set the text color here */
}

Upvotes: 7

byroncorrales
byroncorrales

Reputation: 745

The default class for tooltips is .jqstooltip you can override in your own CSS using !important

Upvotes: 1

sugarenia
sugarenia

Reputation: 21

You can use the tooltipClassname option to add a CSS class to default tooltips and override their styling.

Check http://omnipotent.net/jquery.sparkline/#interactive for more tooltip options.

Upvotes: 2

Related Questions