如何正确链接选择和图表?

时间:2016-01-14 17:21:15

标签: javascript jquery d3.js ember.js

我在Ember.js中构建了一个图表,我将'select'与图表链接起来。这是我的code.

每次单击“选择”中的组时,我都无法仅显示在图表中选择的值。

但每次点击,我都会在先例旁边添加一个新图表。我没看到错误在哪里。

可能是她:

    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,

我该怎么办?

0 个答案:

没有答案