Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making charts in RaphaelJS that are 100% width?

Tags:

raphael

I have seen graphs in Flash & stuff that basically adapt nicely to whatever the size of the browser or flexible element they are inside of.... I'm not really too well versed with raphaelJS but can you do this, and if so, how?

like image 972
Rey Avatar asked Oct 18 '10 20:10

Rey


2 Answers

In raphaeljs, you can call .setSize on a Raphael object to update its size. To adapt to runtime changes in browser window size, you can respond to a window resize event. Using jQuery, you could do:

// initialize Raphael object
var w = $(window).width(), 
    h = $(window).height();

var paper = Raphael($("#my_element").get(0), w,h);

$(window).resize(function(){
     w = $(window).width();
     h = $(window).height();
     paper.setSize(w,h);
     redraw_element(); // code to handle re-drawing, if necessary
});
like image 124
Bosh Avatar answered Sep 28 '22 04:09

Bosh


This will get you a responsive SVG

var w = 500, h=500;
var paper = Raphael(w,h);
paper.setViewBox(0,0,w,h,true);
paper.setSize('100%', '100%');
like image 20
Jake Wilson Avatar answered Sep 28 '22 03:09

Jake Wilson