Making charts in RaphaelJS that are 100% width?

前端 未结 3 933
忘掉有多难
忘掉有多难 2021-02-14 07:12

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 verse

3条回答
  •  半阙折子戏
    2021-02-14 07:31

    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
    });
    

提交回复
热议问题