score:2

Accepted answer

You need to keep track of the updates with some variable inside your closure and use them when updating the chart (currentData, currentType):

$(function () {
    var currentData = dataDaily;
    var currentType = 'spline';

    var chart = c3.generate({
    bindto:'#chart',
    data: {
        x : 'x',
        columns: currentData,

        type: currentType,
        labels:true
    },
    axis: {
        x: {
            type: 'category' // this needed to load string x value
        }
    }
     });


    $("#DataType").change(function (evt) {
        var timeSelection = eval( $("#DataType").val());
        currentData = timeSelection;

        var chart = c3.generate({
        bindto:'#chart',
        data: {
            x : 'x',
            columns: currentData,

            type: currentType,
            labels:true

        },
        axis: {
            x: {
                type: 'category' // this needed to load string x value
            }
        }
    });

    $("#chartType").change(function (evt) {
        var chartSelection = $("#chartType").val();
        currentType = chartSelection;
        var chart = c3.generate({
            bindto:'#chart',
            data: {
                x : 'x',
                columns: currentData,

                type: currentType,
                labels:true

            },
            axis: {
                x: {
                    type: 'category' // this needed to load string x value
                }
            }
    });
});

Related Query

More Query from same tag