2014-02-20 103 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; 
} 

另一種選擇是在點擊(更新)時添加額外的類。