jeudi 14 janvier 2016

How can I linked the select and chart correctly?

I build a chart in Ember.js, I linked a 'select' with the chart. here is my code.

Every time that I click a group in the 'select', I can't display just the value selected in my graph .

But each click, I add a new graph next to the precedent. I didn't see where is the error.

May be her :

    var data  = d3.entries(donnees);

    var GroupArray = [];
    // adding unique group to groupArray
    $.each(data, function (index) {
        var Group = data[index].key;
        if ($.inArray(Group, GroupArray) === -1) {
            GroupArray.push(Group);
        }
    });

    //sorting the Group 
    GroupArray.sort();
    GroupArray.unshift("All");

    var $GroupDropDown = $("#DropDown_group");
    var $container = $("#chart-load");
    // append the Group to select
    $.each(GroupArray, function (i) {
        $GroupDropDown.append('<option value="' + GroupArray[i] + '">' + GroupArray[i] + '</option>');
    });

    $GroupDropDown.change(function () {
        var selectedGroup = this.value;
        //filter select based on selected group
        var selectedArray = selectedGroup === "All" ? data : jQuery.grep(data, function (product, i) {
            return product.key === selectedGroup;
        });
        drawPlot(selectedArray);

    });

    $(document).ready( function ()
    {
      /* we are assigning change event handler for select box */
        /* it will run when selectbox options are changed */
        $('#DropDown_group').change(function()
        {
            /* setting currently changed option value to option variable */
            var option = $(this).find('option:selected').val();
            /* setting input box value to selected option value */
            $('#chart-load').val(option);
        });
    });
    $("#DropDown_group").change(function() {

    });

    // call the method below
    drawPlot(data);

    function drawPlot(data) {

    var w=500,

How can I do?




Aucun commentaire:

Enregistrer un commentaire