byMan / flot

Automatically exported from code.google.com/p/flot
0 stars 0 forks source link

Legend Formatter #297

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
is there a way that I use a formatter function (such as one in Pie label) to 
format legends?
What I actually need is to display the percentage in the legends instead of 
labels in Pie chart..

Best regards,

Original issue reported on code.google.com by nizar.ab...@gmail.com on 1 Feb 2010 at 7:02

GoogleCodeExporter commented 9 years ago
Here is an example of using a custom labelFormatter with flot.pie to show both 
the percent and unchanged value. Of course you could use just one or the other.

var options= {
    series: {
        pie: {
            show: true
        }
    },
    legend: {
        show: true,
        labelFormatter: function(label, series) {
            var percent= Math.round(series.percent);
            var number= series.data[0][1]; //kinda weird, but this is what it takes
            return(''+label+': '+number+' ('+ percent + '%)');
        }
    }
};

var data= [
    {data:123, label:"test1"},
    {data:456, label:"test2"},
    {data:789, label:"test more"}
];

var plot= $.plot(placeholderSelector, data, options);

Hope this helps.

Eddie Canales

Original comment by eddiecan...@gmail.com on 27 Sep 2010 at 6:57

GoogleCodeExporter commented 9 years ago
Thanks for the info.

You might want to avoid using "options" as your variable name as it is a 
reserved word in javascript. Maybe use "flotOptions" instead?

Original comment by keithhop...@gmail.com on 16 Nov 2010 at 4:49

GoogleCodeExporter commented 9 years ago
This seems to have been a question (which would have been better posed at the 
mailing list by the way :), so I'm closing it.

keithhopkin: do you have a source? I've never heard that before, and I couldn't 
find it with a quick search, see for instance 
http://www.quackit.com/javascript/javascript_reserved_words.cfm

Original comment by olau%iol...@gtempaccount.com on 13 Dec 2010 at 3:01

GoogleCodeExporter commented 9 years ago
there more html formating that you can find here
http://www.html-codes-color.com/

Original comment by fr12...@yahoo.com on 11 Feb 2012 at 3:34

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
fast growing social bookmarking website 
http://bookmarkscope.com/

Original comment by nealkata...@gmail.com on 12 Apr 2012 at 6:24

GoogleCodeExporter commented 9 years ago

Original comment by dnsch...@gmail.com on 4 Jun 2012 at 2:39

GoogleCodeExporter commented 9 years ago
Thank a lot for your good information bro.
http://www.to-to-to.com

Original comment by shajimax...@live.com on 31 Aug 2012 at 4:08

GoogleCodeExporter commented 9 years ago
Really helpful info, i resolved my issue. Thank u so much.
http://www.newsbucket.org/

Original comment by newsbuck...@gmail.com on 15 Sep 2013 at 4:06

GoogleCodeExporter commented 9 years ago
Well, you can use html5 canvas to do it, here is demo to do it 
http://www.tutorialspark.com/html5/HTML5_Canvas_Graphs_Charts.php 

Original comment by punter...@gmail.com on 30 Sep 2013 at 10:32