javascriptprimefacesjqplotjqplot-highlighter

Show percentage in jqplot piechart tooltip


I'm using primefaces with jqplot library.

In my piechart i have the extender property and in the javascript function i have this:

this.cfg.highlighter = {
     show:true,
     tooltipLocation: 'n',
     tooltipAxes: 'y',
     useAxesFormatters: false,
     tooltipFormatString: '%s'
}

The tooltip shows section value, but not section percentage.

Anybody knows how to show percentage value in tooltip?

Thanks.


Solution

  • You can bind the highlight event in order to modify the tooltip :

    $("#chart1").bind('jqplotDataHighlight', function(ev, seriesIndex, pointIndex, data) {
     var highlightToolTip = $(".jqplot-highlighter-tooltip");   
     var pct = Math.round(data[1]/total*100);
     highlightToolTip.html(data[0]+", "+pct+"%");  
    });
    

    Where :

    Please see a working example on fiddle here