2014-02-20 57 views
2

我使用jQuery​​来制作饼图。最初我传递默认的配置参数。之后,我想更改饼图的bar-colorsize等配置参数。如何更改jQuery“easy饼图”插件的配置参数?

默认配置参数:

$('.chart').easyPieChart({ 
    easing: 'easeOutCirc', 
    barColor: '#1abc9c ', 
    trackColor: '#f9f9f9 ', 
    scaleColor:false, 
    scaleLength: 5, 
    percent: 67, 
    lineCap: 'round', 
    lineWidth: 15, //12 
    size: 150, //110 
    animate: {duration: 2000, enabled: true}, 
    onStep: function (from, to, percent) { 
     $(this.el).find('.percent').text(Math.round(percent)); 
    } 
}); 

我知道如何设置饼图的percentage值动态,就像在下列方式:

$('#'+domId).data('easyPieChart').update(value); 

除了percentage,我想设置动态配置参数如下:

我想设置size,bar-color饼图动态年。为此我尝试了很多东西,但我没有找到正确的方法。

对于这一点,我做了JSFIddle为understanding.Initially大小点击后应该110redraw按钮需要。但它不工作改变pie chart大小。

告诉我,我使用的插件是否满足我的要求?如果是这样,我该如何解决这个问题?

回答

1

我们必须破坏现有的数据,然后重新创建图表

var $chart = $(".easy-pie-chart"); 
     $chart.data('easy-pie-chart', null); 
     $chart.easyPieChart({ 
      // my new settings here 
     }); 
0

您可以在页面上每个排行榜中设置这些值,每个ID,不仅为类。

var chart = window.chart = $('#easypiechart1').data('easyPieChart'); 
$('.chart')#easyPieChart({ 
barColor: '#333', 
} 

});

另外,您可以从CSS更改这些值。

.easypiechart { 
    position: relative; 
    display: block; 
    width: 100px; 
    height: 100px; 
} 

另一种选择是在点击(更新)时添加额外的类。