easy-pie-chart icon indicating copy to clipboard operation
easy-pie-chart copied to clipboard

Options passed via data attributes or JavaScript

Open simivar opened this issue 9 years ago • 1 comments

Options can be passed via data attributes or JavaScript. For data attributes, append the option name in lowercase to data-, as in data-barcolor="".

simivar avatar Feb 02 '16 13:02 simivar

I was able to achieve this by using a function for barColor option when initialising the chart, and adding "data-barColor" attribute to the chart element.

<div class="chart" id="my-chart" data-percent="-87" data-barcolor="#2BAB00">

$(".chart").easyPieChart({
   barColor: function() {
      return this.el.getAttribute("data-barColor") ? this.el.getAttribute("data-barColor") : "gray";
   }
 });

Note that I'm not using the percentage variable, which seems to prevent the chart from changing from default color to final color as it reaches the target value.

This way when I have many chart elements, it should render each chart with a different color according to the data-barColor value, or gray if the attribute is not set.

josezulu avatar Dec 11 '19 19:12 josezulu