Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 246
Jorge O Avatar asked Jan 13 '23 23:01

Jorge O


2 Answers

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 */
}
like image 119
Mike Robertson Avatar answered Feb 11 '23 12:02

Mike Robertson


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.

like image 30
sugarenia Avatar answered Feb 11 '23 13:02

sugarenia