0

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.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
  • possible duplicate of [How to display tooltips on jqplot pie chart](http://stackoverflow.com/questions/8209474/how-to-display-tooltips-on-jqplot-pie-chart) – explunit Jun 11 '14 at 11:45
  • I saw that post, it's not duplicated, i want to show another data. Thansk. – JuanRonline Jun 11 '14 at 12:55

1 Answers1

2

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 :

  • data1 is the value of the highlighted slice,
  • data[0] is the label of the highlighted slice,
  • total is a variable containing the total value of your plot built here :

     data = [
        ['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14], 
        ['Out of home', 16],['Commuting', 7], ['Orientation', 9]
    ];
    
    var total = 0;
    $(data).map(function(){total += this[1];})
    

Please see a working example on fiddle here

Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
AnthonyLeGovic
  • 2,335
  • 1
  • 13
  • 22
  • Doesn't seem to work anymore. I had to change `jqplotDataHighlight` tot `jqplotDataMouseOver`. I wonder if there's a better way. – Rob N Jan 16 '17 at 23:20