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

Add series data as parameter of labelInterpolationFnc #22

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

Conversation

zedentox
Copy link

@zedentox zedentox commented Mar 1, 2018

This PR allows to choose different labels depending on the series.

Chartist.plugins.ctPointLabels({
    labelInterpolationFnc: function(value, serie) {
        if (serie.name === 'series-dollars') {
            return '$ ' + value;
        }
        if (serie.name === 'series-euros') {
            return value + ' €';
        }
        return value;
    }
})

I used grunt default to passe tests and build dist sources.
I tested this feature with a simple Bar chart and a multiline Line chart. I also tested if no errors occurs when no serie names are present. Seems ok to me.

@joelstein
Copy link

I have a use case which requires the additional data in the 'data' variable, not just the series. I would recommend passing in data, from which you can easily get the series, index, and other values. For example, I want this so I can show a point label of the percentage increase from the previous item in the series, which would be easy to calculate if I had the whole data variable.

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