Mea Gerchap
Mea Gerchap

Reputation: 23

D3 - Make Axes Include Origin at (0,0)

The following scatterplot example has origin at (2, 4) truncating the graph

even though range specifies zero.

.range([0, width]); .range([height, 0]);

http://bl.ocks.org/mbostock/3887118

Question ----> How to make origin start at (0,0) regardless of data

similar to the following example:

http://bl.ocks.org/hunzy/11110940

also with the same range

.range([0, width]); .range([height, 0]);

Upvotes: 2

Views: 1570

Answers (1)

huan feng
huan feng

Reputation: 8623

Does this help?

y.domain([0, d3.max(data, function (d) {
        return d.y;
    })])
.nice();
x.domain([0, d3.max(data, function (d) {
        return d.x;
    })])
.nice();

Upvotes: 4

Related Questions