D3 linechart string domain x-axis

If you want to use categorical values on an axis, you need a categorical (ordinal) scale. Have a look at the documentation. Your code would look something like

var x = d3.scale.ordinal().rangeRoundBands([0, width]);
var xAxis = d3.svg.axis().scale(x).orient("bottom");

x.domain(data.map(function(d) { return d.country; }));

Note that this uses map to extract the string values -- this may or may not be implemented in your particular browser, see here for more details.


Use

var x = d3.scale.ordinal().rangePoints([0, width]);

Here is Fiddle Link http://jsfiddle.net/sk2Cf/