Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adapting text to highchart tooltip max width

Tags:

highcharts

I wanna adapt vertically the text in my highcharts tooltip (a max-width is defined, so if text does not fit to this max width, increase tooltip height to fit the text in)

What works for simple HTML stuff...

#my_div
{
   height:auto;
   max-width:140px;
   overflow:auto
}

does not work for highcharts tooltips, see http://jsfiddle.net/perikut/hNCDb/2/

like image 788
user1249791 Avatar asked Feb 09 '13 17:02

user1249791


3 Answers

Simply add this to the chart options:

tooltip:{
    shared: false,
    useHTML: true
}

Then add the following to your CSS:

.highcharts-tooltip span {
    height:auto !important;
    width:140px !important;
    max-width:140px !important;
    overflow:auto !important;
    white-space:normal !important; 
}

You are good to go! ;-)

like image 178
Arcel Maendeleo Avatar answered Oct 13 '22 02:10

Arcel Maendeleo


default white-space is set nowrap, you should change it to normal.

.highcharts-tooltip span {
    height:auto;
    width:140px;
    background-color:green;
    overflow:auto;
    white-space:normal !important; // add this line...
}

DEMO

like image 40
AliRıza Adıyahşi Avatar answered Oct 13 '22 00:10

AliRıza Adıyahşi


If you only want to change the white-space behavior ofthe tooltip for a single chart and/or seperately control the style for each individual chart, you can use the following approach:

 tooltip: {
    useHTML: true,
    formatter: function() {
        return "<div style='width: 400px; white-space:normal;'>" + this.points[0].point.yourDataPointValue + "</div>";
    }  
 }

Demo

Note that you can/should use use a class name versus an inline style if you want to reuse the same style for multiple tooltips.

like image 40
Tim M. Avatar answered Oct 13 '22 02:10

Tim M.