diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-02-23 10:47:44 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-02-23 10:47:44 +0100 |
commit | 60365f7ee8b34a3d4c92fde708e5fa7110e0ce34 (patch) | |
tree | 2571bf2b308e8efe405fcb4d85db096ca464d0d1 /public | |
parent | 5fb74f4f347453f44ab8f86fff0448218cf86d12 (diff) |
proper number formatting
Diffstat (limited to 'public')
-rw-r--r-- | public/js/d3funcs.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/public/js/d3funcs.js b/public/js/d3funcs.js index 4fafb42..15fe5eb 100644 --- a/public/js/d3funcs.js +++ b/public/js/d3funcs.js @@ -1,10 +1,9 @@ -show_bargraph = function(datasource, title, xlab, ylab) { +show_bargraph = function(datasource, title, xLabel, yLabel, yFormat) { + var margin = {top: 40, right: 20, bottom: 30, left: 40}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; - var formatPercent = d3.format(".0%"); - var x = d3.scale.ordinal() .rangeRoundBands([0, width], .1); @@ -18,7 +17,10 @@ show_bargraph = function(datasource, title, xlab, ylab) { var yAxis = d3.svg.axis() .scale(y) .orient("left"); - // .tickFormat(formatPercent); + + if (yFormat) { + yAxis = yAxis.tickFormat(d3.format(yFormat)); + } var tip = d3.tip() .attr('class', 'd3-tip') @@ -48,7 +50,7 @@ show_bargraph = function(datasource, title, xlab, ylab) { .attr("x", width / 2) .attr("y", 30) .style("text-anchor", "middle") - .text(xlab); + .text(xLabel); svg.append("g") .attr("class", "y axis") @@ -58,7 +60,7 @@ show_bargraph = function(datasource, title, xlab, ylab) { .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") - .text(ylab); + .text(yLabel); svg.append("text") .attr("x", (width / 2)) |