Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options passed via data attributes or JavaScript #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Options passed via data attributes or JavaScript #170

wants to merge 1 commit into from

Conversation

simivar
Copy link

@simivar simivar commented Feb 2, 2016

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

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants