javascript – gRaphael饼图动态大小
作者:互联网
我想在一些事件后放大gRaphael pie chart,点击例如.但是gRaphael饼图是在窗口加载后创建的,具有静态宽度和高度.是否可以实时动态重绘?
我的代码:
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
当然我可以在点击当前图表后删除并创建新的,但这不是一种方式,因为我需要在其他点击后返回原始大小.
解决方法:
你只需要清除&像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"
}
);
});
当然,数据和选项应该分解并放在全球可用性范围内.
标签:jquery,javascript,pie-chart,graphael 来源: https://codeday.me/bug/20190709/1416046.html