Skip to content

Instantly share code, notes, and snippets.

@yojimbo87
Created January 1, 2012 16:05
Show Gist options
  • Save yojimbo87/1547668 to your computer and use it in GitHub Desktop.
Save yojimbo87/1547668 to your computer and use it in GitHub Desktop.
var barWidth = 64,
width = (barWidth + 10) * dataTotalViewsCount.length,
height = 300;
var x = d3.scale.linear()
.domain([0, dataTotalViewsCount.length])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, d3.max(dataTotalViewsCount, function (d) { return d.count; })])
.rangeRound([0, height]);
var chart = d3.select("#chart-total-views-count")
.append("svg:svg")
.attr("width", width)
.attr("height", height + 30);
chart.selectAll("rect")
.data(dataTotalViewsCount)
.enter()
.append("svg:rect")
.attr("x", function (d, index) { return x(index); })
.attr("y", function (d) { return height - y(d.count); })
.attr("height", function (d) { return y(d.count); })
.attr("width", barWidth)
.attr("fill", "#2d578b");
chart.selectAll("text")
.data(dataTotalViewsCount)
.enter()
.append("svg:text")
.attr("x", function (d, index) { return x(index) + barWidth; })
.attr("y", function (d) { return height - y(d.count); })
.attr("dx", -barWidth / 2)
.attr("dy", "1.2em")
.attr("text-anchor", "middle")
.text(function (d) { return d.count; })
.attr("fill", "white");
chart.selectAll("text.yAxis")
.data(dataTotalViewsCount)
.enter().append("svg:text")
.attr("x", function (d, index) { return x(index) + barWidth; })
.attr("y", height)
.attr("dx", -barWidth / 2)
.attr("text-anchor", "middle")
.attr("style", "color: red;font-size: 12;")
.text(function (d) { return d.kiosk; })
.attr("transform", "translate(0, 18)")
.attr("class", "yAxis");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment