d3JS带有顺序标度的直方图 [英] d3JS Histogram with ordinal scale

查看:263
本文介绍了d3JS带有顺序标度的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到一个D3JS直方图,使用一个顺序量表(在这种情况下,学生成绩符号(A +,A,B ... F)。

I am trying to get a D3JS histogram working with an ordinal scale (in this case, student grade symbols (A+, A, B ... F).

以下是最低工作示例:

<!DOCTYPE html>
<meta charset="utf-8">

<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
    var studentSymbols = ["F", "E", "D", "C", "C", "C", "C", "B", "B", "A", "A+"];

    var x = d3.scale.ordinal()
        .domain(["F", "E", "D", "C", "B", "A", "A+"])
        .rangeRoundBands([0, width]);

    // Generate a histogram using twenty uniformly-spaced bins.
    var myHistogram = d3.layout.histogram()
        (studentSymbols);

    console.log(myHistogram)
</script>
</body>

当上面的代码运行时,控制台输出一个5个数组的数组,

When the above is run, the console outputs an Array of 5 Arrays, with dx and x fields equal to NaN.

推荐答案

我想我可能想出来了。我将myHistogram的声明改为:

I think I may have figured it out. I changed the declaration of myHistogram to:

    var myHistogram = d3.layout.histogram()
        (studentSymbols.map(x));

这篇关于d3JS带有顺序标度的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆