youcef92 / flotr

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

Dynamic Pie Charts - each slice is a series? #115

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I've been digging through the code of flotr (and plotr) for a few days now. I'm 
just learning 
javascript and it's a terrible idea to jump into the middle of the lake when 
you want to learn to 
swim, but here I am...

I have a form where users fill in percents. I then have a function which walks 
through the form and 
gets the percents and places them into an array. I was hoping to then turn this 
array into a pie 
chart, but I'm not sure if I can do that with flotr, anymore.

My experimentation has shown me that each data set has to be a different 
variable on it's own, the 
code doesn't like arrays... Since my chart is dynamic, I really don't see a 
simple way to go about 
doing this.

Am I mistaken on this issue?

Original issue reported on code.google.com by prw...@gmail.com on 14 Feb 2010 at 2:33

GoogleCodeExporter commented 8 years ago
Yes, each slice is a series, so that it can have a color and a legend entry. 
Get inspiration from the basic-pie.html example.

Flotr.draw($('container'), [
    {data: [[0, 5]], label: 'Comedy'}, 
    {data: [[0, 1.2]], label: 'Action'}, 
    {data: [[0, 3]], label: 'Romance'}, 
    {data: [[0, 1]], label: 'Drama'}
], {
    xaxis: {showLabels: false},
    yaxis: {showLabels: false}, 
    pie: {
        show: true
    }
});

It means: Comedy=5, Action=1.2, Romance=3, Drama=1.
Note that each data is an array with only one entry which is an array with two 
entries : 0 on the first key and the value on the second.

Original comment by fabien.menager on 16 Jul 2010 at 7:25