Quantcast
Channel: User i alarmed alien - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by i alarmed alien for Line chart function pulling out data from different columns

$
0
0

You don't need the " around the "function(d) { return y(d."+city+"); }" -- that tells javascript to interpret the text function(d) { return y(d. and ); } as a string, giving a y attribute of function(d) { return y(d.london); }. You want to perform the function, rather than just quote it.

To access the data for the city, you need to access

d['london']

from the object d (it can also be written as d.london). Since city is a variable storing the name of the current city, you can do this using

d[city]

The whole line is thus

.y(function(d) { return y(d[city]); });

Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>