draw radial line

27 views
Skip to first unread message

Noel Yu

unread,
Apr 9, 2017, 2:01:57 PM4/9/17
to d3-js
Hi, 

I have some issues on drawing the radial line. I basically follow the sample codes here: https://bl.ocks.org/d3indepth/39d798286a4bf92cee446add65290d70

but the `point` is different. I am trying to put functions in [ ].

My codes here are: var points = [[Math.PI*2*(i/366), (deata, function(d){if (d.depDelay >= 0){return d.depDelay;}})]];

Math.PI*2*(i/366) means I divided the circle into 366 which is the number of my data.
(data, function(d){if (d.depDelay >= 0){return d.depDelay;}})  means I draw the height of line by depDelay (which is a field in my data) and only show the positive depDelay


I have been stuck in this codes for a couple of days. It seems I have problems in dealing with data by using js but I cannot find any solutions online. I appreciate any help, thank you!


-Zhengyan

steve rickus

unread,
Apr 10, 2017, 9:30:29 AM4/10/17
to d3-js
So it looks like you just want to build an array of points from your input data, correct? You don't need to use any D3 libraries for this, just a plain old javascript map() function. Assuming your input data is an array of 366 objects containing depDelay fields, you can use something like this (untested):

var points = data.map(function(d, i) {
 
var angle =
Math.PI*2*(i/366);
  var delay = d.depDelay > 0? +d.depDelay: null; // defaults to null, so the point does not show?
 
return [angle
, delay];
});

There are other basic array functions that may be more suited to your incoming data, but I don't know what your data looks like. Here is a good reference that I use often while manipulating javascript arrays:

Steve
Reply all
Reply to author
Forward
0 new messages