javascript - D3.js circles order -


i have follow json array

{"x" :"7","y" :30,"color" : "green"},{"x" :"8","y" :70, "color" : "purple"},  {"x" :"9","y" :50, "color" : "yellow"},{"x" :"10","y" :60, "color" : "black"}  

but when draw circles, d3.js order array "y" parameter

example : correct order should

    green -> purple -> yellow - black 

but d3.js show

     green -> yellow -> black -> purple 

snippet fiddle

d3 displaying circles correctly vertical order based on y value , not on order in array.

you're defining here:

.attr("cy", function (d) { return d.y; })                        

if draw circles in indices order

.attr("cy", function (d, i) { return *10 + 100; })                        

here have multiplied index constant (10) circles drawn request.

jsfiddle


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -