简体   繁体   中英

Filtering the d3 bubble chart as we type

I am trying to filter the bubble chart as we type into a text box. With every keystroke that we type, the bubble chart should be updated with the nodes whose name value matches the expression typed so far.

This is what I am trying, but it doesn't seem to be working. Is there any other way of doing this?

var selectedVal = document.getElementById('autocompleteInput').value;
var regexp = new RegExp("^" + selectedVal.toLowerCase() + "\\w*");
var updatedData = feedsChart['children'].filter(function(obj){
         return regexp.test(obj['name'].toLowerCase());
                });
var newObj = {"children":updatedData,"name":"All Feeds"};
drawBubble(newObj); // This function redraws the entire bubble chart

I believe you need to tie the function that updates your chart to the onkeyup event. With jquery it might look like this

d3.select("#autocompleteInput").on("keyup", drawBubble);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM