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

Making c3 reactive #4

Open
FickleLife opened this issue Nov 1, 2014 · 0 comments
Open

Making c3 reactive #4

FickleLife opened this issue Nov 1, 2014 · 0 comments

Comments

@FickleLife
Copy link

I have some code in a template helper:

var chart;

function chartData() {
    var data = {
        "Placed": Counts.get('placed'),
        "Refunded": Counts.get('refunded')
    }
    return data;
}


function chartRefresh() {
    chart.load({
        json: chartData()
    });
}

Template.chart_entrant_status.rendered = function() {
    chart = c3.generate({
        transition: {
            duration: 1000
        },
        bindto: 'div#chart',
        data: {
            json: chartData(),
            type : 'donut',
            onclick: function (d, i) { console.log("onclick", d, i); }
            // onmouseover: function (d, i) { console.log("onmouseover", d, i); },
            // onmouseout: function (d, i) { console.log("onmouseout", d, i); }
        },

        legend: {
            show: false
        },
        donut: {
            label: {
                format: function (value, ratio) {
                    return value;
                }
            }
        }
    });

    this.autorun(function() {
        chartRefresh();
    });
};

This works well - the chart is reactive. However I get a lot of errors in the console when the data changes

Error: Invalid value for <path> attribute d="MNaN,NaNA145.35,145.35 0 1,1 NaN,NaNLNaN,NaNA87.21,87.21 0 1,0 NaN,NaNZ"

Over and over again. I think it has something to do with the drawing of the chart when it's not created... Can anyone shed any light? Thanks

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

No branches or pull requests

1 participant