我尝试重新实现我在网上找到的这个图表:http://plnkr.co/edit/5g4lUXnJa3pmWEfFq8rq?p=preview基本上,我所做的就是将我的x轴改为字符串而不是整数。
// set the stage
var margin = {t:30, r:20, b:20, l:40 },
w = 600 - margin.l - margin.r,
h = 500 - margin.t - margin.b,
x = d3.scale.ordinal().rangeRoundBands([0,w], .1) //changed linear to ordinal to accept strings input
y = d3.scale.linear().range([h - 60, 0]),
//colors that will reflect geographical regions
color = d3.scale.category10();
.....
var x0 = Math.max(-d3.min(data, function(d) { return d.trust; }), d3.max(data, function(d) { return d.trust; }));
x.domain(["Drug A", "Drug B", "Drug C", "Drug D", "Drug E", "Drug F"]); //changed this to strings
y.domain([0, 250])