Zack
Zack

Reputation: 114

Using setData in HighCharts multiple times

In my example http://jsfiddle.net/uwdz8rm8/, I'm only able to get setData to run once. I would like to switch between two data sets. Any ideas?

The jQuery I have is proven working in my test div but not on Highcharts

$('input:radio[name=penetrationoptions]').change(function () {
    var chart = $('#KPI_Penetration_Chart').highcharts();
    if (this.value == 'amount') {
        chart.series[0].setData(amountData);
        $('#testing').css("background", "red");
    } else if (this.value == 'count') {
        chart.series[0].setData(countData);
        $('#testing').css("background", "green");
    }
});

Thanks for the help!

Upvotes: 1

Views: 572

Answers (1)

Ryley
Ryley

Reputation: 21216

Try this:

    $('#KPI_Penetration_Chart').highcharts({
        chart: {
            type: 'pie'
        },

        series: [{
            data: $.extend(true,[],amountData)
        }]
    });

All I changed is to copy amountData the first time. You'll discover that both variables end up pointing to the same data set if you don't.

See it working here: http://jsfiddle.net/uwdz8rm8/3/

Upvotes: 1

Related Questions