D3.js从csv文件中读取数据

时间:2015-12-08 10:16:49

标签: javascript html d3.js svg

我尝试重新实现我在网上找到的这个图表: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])

但现在我似乎对数据绘图有问题。数据当前仅在我应该根据我更改的字符串显示时显示在我的Y轴上。请参见此处的图片:Click to view Image

0 个答案:

没有答案