Return data based on dropdown menu?

后端 未结 1 352
花落未央
花落未央 2020-12-29 00:05

I am building a basic scatter plot where I\'d like to highlight specific points in my plot based on a dropdown selection. My code looks like this:

fill_arr =         


        
1条回答
  •  囚心锁ツ
    2020-12-29 00:55

    Access it using this.selectedIndex:

    d3.select('select')
        .on("change", function() {
    
        key = this.selectedIndex;
    
        d3.selectAll('circle')
            .transition()
            .duration(300)
            .ease("quad")
            .attr( 'r', 5)
            .attr('cx', function(d) {return d.x;})
            .attr('cy', function(d) {return d.y;})
            // if a data point is selected highlight other 
            // data points of the same color
            .style('fill', function(d, i) { 
                if (d.label == key) 
                {return fill_arr[key]}
                else {return "#ccc"}
            ;})
    });
    

    0 讨论(0)
提交回复
热议问题