parsing - D3 remove comma delimiters for thousands -
i have .json 3 columns 1 of them 'year'. column contains years. no dates!.
when graphing on 'x' axis years come out comma delimiter thousands.
so in .json date format :"year":1990 , on 'x' axis comes out 1,990
i have been trying figure out how parse year have no luck far. have tried following:
var parsedate = d3.time.format("%y").parse var x = d3.time.scale() .range([0, width]); //further down d3.json("waterdata.json", function(error, json) { // attach data var data = json.data; // select data x , y var axis1 = 'year'; var axis2 = 'ratio' // convert string numbers data.foreach(function(d) { ///axis1 = parsedate(axis1); d[axis1] = +d[axis1] d[axis2] = +d[axis2] }); x.domain(d3.extent(data, function(d) { return d[axis1]; })); y.domain(d3.extent(data, function(d) { return d[axis2]; })); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + (height+10) + ")") .call(xaxis) .append("text") .attr("class", "label") .attr("x", width) .attr("y", -40) .text(axis1) svg.append("g") .attr("class", "y axis") .attr("transform", "translate("+ -10 + "," + 0 + ")") .call(yaxis) .append("text") .attr("class", "label") .attr("x", 10) .style("fill", "#666") .style("text-anchor", "start") .text(axis2)
any suggestions of how rid of comma delimiter. or figure out how parse date.
you should add .tickformat(d3.format("d"))
xaxis:
var xaxis = d3.svg.axis().scale(x).orient("bottom").tickformat(d3.format("d"));
Comments
Post a Comment