javascript - How to put string label on X axis in d3 -
i using scatter plot d3 , i'm trying label x axis of plot string can read csv file.
here code current implementation:
var xvalue = function(d) { return d.age;}, // data -> value xscale = d3.scale.linear().range([0, width]), // value -> display xmap = function(d) { return xscale(xvalue(d));}, // data -> display xaxis = d3.svg.axis().scale(xscale).orient("bottom"); var yvalue = function(d) { return d["income"];}, // data -> value yscale = d3.scale.linear().range([height, 0]), // value -> display ymap = function(d) { return yscale(yvalue(d));}, // data -> display yaxis = d3.svg.axis().scale(yscale).orient("left"); d3.csv("predict_plot_h1b.csv", function(error, data) { // x-axis // y-axis // other d3 elements });
this gives me (only x axis labels important in plot below):
this csv data looks like:
age, income 72, 2 50, 1 55, 3 50, 2 80, 2
so on here want use exact age labels instead of using range 50 80.
how can modify code x axis label appear 50 55 72 80 instead of 50 60 70 80
Comments
Post a Comment