简体   繁体   English

gRaphael饼图动态大小

[英]gRaphael pie chart dynamic size

I want to enlarge gRaphael pie chart after some event, click for example. 我想在一些事件后放大gRaphael饼图 ,点击例如。 But gRaphael pie chart is creating after window load with static width and heigh. 但是gRaphael饼图是在窗口加载后创建的,具有静态宽度和高度。 Is it possible to dynamic redraw it in real time? 是否可以实时动态重绘?

My code: 我的代码:

var myRadius;

myRadius = 200;

var myChart = Raphael("myChartDiv"), 
    myChartPie = myChart.piechart(
        myRadius, // cx
        myRadius, // cy
        myRadius, //Radius
        [70, 30], //Data    
        {           
        colors: ["#eb5e57", "#ebad50"],         
        stroke: "#f1eeea"       
        }
    );

$('#myButton').click(function(){
     myRadius = 500; 
     myChart.clear(); //Clear current canvas
     // Do something to insert myChart with new myRadius
});

UPD Ofcourse I can remove after click current chart and create new, but it's not a way, because I will need to back original size after other click. UPD Ofcourse我可以在点击当前图表后删除并创建新的,但这不是一种方式,因为我需要在其他点击后返回原始大小。

You just need to clear & redraw your pie as on this fiddle . 你只需清理和重绘你的馅饼就像这个小提琴一样

var myRadius;

myRadius = 200;

var myChart = Raphael("myChartDiv"), 
    myChartPie = myChart.piechart(
        myRadius, // cx
        myRadius, // cy
        myRadius, //Radius
        [70, 30], //Data    
        {           
            colors: ["#eb5e57", "#ebad50"],         
            stroke: "#f1eeea"       
        }
    );

$('#myButton').click(function(){
    if(myRadius == 200)
         myRadius = 500; 
    else
        myRadius = 200;
    myChart.clear();
    myChartPie = myChart.piechart(
        myRadius, // cx
        myRadius, // cy
        myRadius, //Radius
        [70, 30], //Data    
        {           
            colors: ["#eb5e57", "#ebad50"],         
            stroke: "#f1eeea"       
        }
    );
});

Of course, data and options should be factorized and put in global scope for usability. 当然,数据和选项应该分解并放在全球可用性范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM