I am attempting to filter a dataset based on a clickable legend embedded in the same svg plot as the graph, I can create the graph, interactive legend and import the data all successfully but when I try to combine the legend with the graph the interactivity fails to filter the data.
I currently have it working by having the interactive legend in one cell and then calling the filter in the graph cell but I want the legend to be on the graph and not above it in another cell.
The horizontal legend will filter correctly, but the legend on the plot while interactive does not filter and I cannot call the array within the same cell it is created.
Any help as to how to best implement this would be greatly appreciated!
Can I delete this post? I donât see the optionâŚ
I have moved onto another way of implementing this based off the Introduction to D3, Part 2 / UW Interactive Data Lab / Observable notebook;
but like the above implementation I can get close to what I want but not quite there. Learning d3 is proving more difficult than I had anticipated.
My new approach is failing in the SelectionModel for the graph always evaluating to false with the line:
//helpâŚ
selmodel.on(âchange.chartâ, () => {
counties.attr(âfillâ, d => selmodel.has(d.prname) ? color(d.prname) : â#cccâ); //selection model never evaluates
//to trueâŚ
});
being where I think the issue lies but I canât pin down.
This response is based on your first post. Judging from your second post, youâre closer but not quite there yet. The approach described here is quite general, though.
If you have two outputs that youâd like to display as one, you can always combine them into a single DIV and use CSS to display them however you like. Hereâs an example using a fork of your first notebook:
Personally, I rarely do this in a notebook, preferring to do so when I embed the output in a webpage using the Javascript runtime. The idea is the same, though.
Thank you for this! I knew there had to be some way of combining multiple viewof in a container but I am so new to d3 and javascript I didnât even know where to begin looking for a solution.