2

I am using jquery.flot.js (v 1.1) for graphs and for tooltip jquery.flot.tooltip.js (version: 0.6.7)

I wanted to show percentage area covered by each stack in stacked graph. I have tried it using %p. But it's not working, it return "%p" in tooltip. Code snippet:

tooltip: true,
tooltipOpts: {
  content: "%s : %y : %p.1%"
}

My graph is-

enter image description here

Could any one help me please ?

sunil
  • 1,040
  • 9
  • 20

1 Answers1

2

You can use %p only if you also use pie charts plugin http://www.flotcharts.org/flot/examples/series-pie/index.html, that placeholder was introduced only to support that plugin. I see that is not clear in the documentation.

In your case you need to count percentage value by yourself. You may use callback function for that. The format is function(label, xval, yval, flotItem) and must return a string in correct format (needed by tooltip).

Hope it helps!

krzysu
  • 402
  • 4
  • 9
  • Thank you for reply. I have tried %p also but it doesn't work, don't know why its not working. I can't use function because, I wanted to show the percentage area covered by each stack in bar. ex: last bar height = 78 then percent value of green stack should be (64/78)*100 = 82 – sunil Mar 27 '14 at 06:32
  • In the function i cant access value of other stack in the same bar. Is that accessible ? – sunil Mar 27 '14 at 07:15
  • Once again, `%p` works only with pie charts. You don't have pie chart so it won't work. I don't know if you can access value of other stacks, check i.e. what you get in `flotItem` object. But you also have access to raw data that you pass to flot, so you could use them (?). Don't rely only on tooltip plugin, use data that you have. – krzysu Mar 27 '14 at 12:03