BENZ.404
BENZ.404

Reputation: 503

Understanding a multi-line d3 chart example

For example - The below link is a multi-line chart displaying 3 indicators (New York, San Francisco, Austin)

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

If I wanted to put a 4th indicator on top of Austin (a moving average) where in the code structure (what area so not to cause error) would I put the equation?

And how would I go about displaying the 4th line as it is not conventional to the behavior of the other indicators as they are drawn via d3.tsv("data.tsv", and data.forEach

I ask a question like this because I keep playing with these things but end up breaking them I can't seem to quite get-my-foot-in-the-door with the docs yet reading isn't totally helping I think because this is more visual than the javascript I am used to and it is a pity that there are few-zero notes at all in the example.

Upvotes: 0

Views: 405

Answers (1)

FernOfTheAndes
FernOfTheAndes

Reputation: 5015

Here is a plunker for this interesting question. (Average in red.)

...
d3.tsv("data.tsv", function(error, data) {
    data.forEach(function(d) {
        d.date = parseDate(d.date);
        d.AVERAGE = (+d["New York"] + +d["San Francisco"] + +d["Austin"]) / 3;
    });
...

Upvotes: 1

Related Questions