line.x([x])
If x is specified, sets the x accessor to the specified function or number and returns this line generator. If x is not specified, returns the current x accessor, which defaults to:
function x(d) { return d[0]; }
When a line is generated, the x accessor will be invoked for each defined element in the input data array, being passed the element d
, the index i
, and the array data
as three arguments. The default x accessor assumes that the input data are two-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor. For example, if x
is a time scale and y
is a linear scale:
var data = [ {date: new Date(2007, 3, 24), value: 93.24}, {date: new Date(2007, 3, 25), value: 95.35}, {date: new Date(2007, 3, 26), value: 98.84}, {date: new Date(2007, 3, 27), value: 99.92}, {date: new Date(2007, 3, 30), value: 99.80}, {date: new Date(2007, 4, 1), value: 99.47}, … ]; var line = d3.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.value); });
Please login to continue.