简体   繁体   中英

d3js bar chart with brush slider

By looking at the following example http://bl.ocks.org/mbostock/4349545 , I am trying to replace the circles with a bar chart, representing events per day, for a couple of years worth of data. Data is the the format

 {"15/01/2015: 214","22/03/2016: 30",..}

Can someone please point me in the right direction?

Thank you!

You can get bar chart by swapping data with new set:

var data = [{ "date" : "15/01/2015", "value" : 214}
        ,{ "date" : "22/03/2016", "value" : 30}]

parse date , change x axis to datetime, and then by change type of circle to Rect(with new attributes etc.) in this place:

var circle = svg.append("g").selectAll("circle")
.data(data)
.enter().append("circle")
.attr("transform", function(d) { return "translate(" + x(d) + "," + y() + ")"; })
.attr("r", 3.5);

But, in the example that you brought brushg use selectAll on all elements of type Rect, so it will be in the conflict with new approach.

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