-->

DC.js scatterPlot ordinal axis tick position

2019-05-08 22:55发布

问题:

How can I position the value points directly above the ticks (or the ticks directly under the points), using DC.js. I could not manage that, DC.js (or D3.js) positions the value points shifted to the left of the ticks, although the X-value is exactly the tick value.

Important: I need this feature for ordinal X axis (it works fine for linear X axis)!

var data = [
  {"x":"a","y":1},
  {"x":"b","y":2},
  {"x":"c","y":3}
];
...
dc.scatterPlot("#mychart")
  .dimension(dimension) 
  .group(group) 
  .x(d3.scale.ordinal().domain(data.map(function(v) {return v.x})))
  .xUnits(dc.units.ordinal) 
  .valueAccessor(function(d) {return d.value;});

Complete code see jsfiddle: http://jsfiddle.net/bourbert/59Lmt98w/1/

回答1:

In dc.js Bubble Chart modify bubbleLocator:

var bubbleLocator = function (d) {
return 'translate(' + (bubbleX(d)+20) + ',' + (bubbleY(d)) + ')';
};