Using an ordinal scale ('d3.scale.ordinal') for the x-axis in a bar chart

后端 未结 2 1641
Happy的楠姐
Happy的楠姐 2020-12-09 17:06

I have a data array like this:

var data = [{\"Alphabet_Type\":\"a\"}, {\"Alphabet_Type\":\"b\"}, {\"Alphabet_Type\":\"a\"}];

I am using:

2条回答
  •  离开以前
    2020-12-09 17:18

    Two things:

    1. Pass dc.units.ordinal as the parameter to .xUnits().
    2. Pass an ordinal scale function to .x().

    Here's what I mean:

    .x(d3.scale.ordinal().domain(["", "a", "b", "c"])) // Need empty val to offset first value
    .xUnits(dc.units.ordinal) // Tell dc.js that we're using an ordinal x-axis
    

    See this JSFiddle: http://jsfiddle.net/reblace/tbamW/156/

    For some reason, I couldn't get renderHorizontalGridLines() or renderVerticalGridLines() to work, but the rest is good.

提交回复
热议问题