Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent ordering in gRaphael pie chart

I'm trying to draw two pie charts using gRaphael, like so:

var r = new Raphael(0, 0, '100%', '100%'); 

r.piechart(100,120,80,[60,40]);
r.piechart(300,120,80,[40,60]);

This produces the following picture:

Mmmmmm, pie

The two pie charts are identical even though the order of the arguments I passed to r.piechart is different. Is there any way I can prevent this from happening so that one of the charts will have the 60% blue slice on the bottom and the other one will remain as it is?

like image 388
RoyalTS Avatar asked Feb 17 '23 11:02

RoyalTS


1 Answers

Here is a fiddle. I'm not a gRaphael expert, so there might be a better way.. I changed the piechart function (line 99 of g.pie.js) from

values.sort(function (a, b) {
    return b.value - a.value;
}); 

to

if (opts.sort !== false) {
    values.sort(function (a, b) {
        return b.value - a.value;
    });
}

And than changed your code to:

r.piechart(100,120,80,[60,40], {sort: false});
r.piechart(300,120,80,[40,60], {sort: false});
like image 148
Amit Aviv Avatar answered Feb 28 '23 08:02

Amit Aviv