score:1

Accepted answer

I did a similar job where I had links and I could select one of the links to select the appropriate JSON to use for the plot. Below is the HTML snippet of interest -

<ul class="dropdown-menu" role="menu">
                    <li><a class="m" value="2014-02-19" href="#">2014-02-19</a></li>
                    <li><a class="m" value="2014-02-20" href="#">2014-02-20</a></li>
                    <li><a class="m" value="2014-02-21" href="#">2014-02-21</a></li>
                    <li><a class="m" value="2014-02-22" href="#">2014-02-22</a></li>
                    <li><a class="m" value="2014-02-23" href="#">2014-02-23</a></li>
                </ul>
...

This is the Javascript snippet doing the selection -

        //On click, update with new data            
        d3.selectAll(".m")
            .on("click", function() {
                var date = this.getAttribute("value");

                var str;
                if(date == "2014-02-19"){
                    str = "19.json";
                }else if(date == "2014-02-20"){
                    str = "20.json";
                }else if(date == "2014-02-21"){
                    str = "21.json";
                }else if(date == "2014-02-22"){
                    str = "22.json";
                }else{
                    str = "23.json";
                }

                d3.json(str,function(json){

                    dataset = json;
                    stack(dataset);
                    ...

Hope this helps.


Related Query