By Bradley Marques


2015-03-28 14:23:00 8 Comments

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

Here is a minimum working example:

<!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>

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

How should I correct this code?

1 comments

@Bradley Marques 2015-03-28 14:31:14

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

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

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Histogram with ordinal data

9 Answered Questions

[SOLVED] Difference between InvariantCulture and Ordinal string comparison

9 Answered Questions

[SOLVED] Histogram using gnuplot?

7 Answered Questions

[SOLVED] Histogram with Logarithmic Scale and custom breaks

1 Answered Questions

[SOLVED] Histogram using d3js

1 Answered Questions

[SOLVED] D3.js Trying to use histogram layout to draw rectangles

  • 2016-10-08 04:38:07
  • ehhpitome
  • 258 View
  • 2 Score
  • 1 Answer
  • Tags:   javascript d3.js

1 Answered Questions

[SOLVED] D3 Ordinal Scales with Scatter Plot

Sponsored Content