Built with blockbuilder.org
-
-
Save jonasius/8d136aba3a38c2a91a59eb3dbc202496 to your computer and use it in GitHub Desktop.
nested data svg example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| var data_lowest = [ | |
| [{key:"Key1", values:["1a","1b","1c"]}], | |
| [{key:"Key2", values:["2a","2b","2c"]}, {key:"Key21", values:["21a","21b","21c"]},{key:"Key22", values:["22a","22b","22c"]}], | |
| [{key:"Key3", values:["3a","3b","3c"]}], | |
| [{key:"Key4", values:["4a","4b","4c"]},{key:"Key41", values:["41a","41b","41c"]}] | |
| ]; | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", 960) | |
| .attr("height", 500) | |
| // console.log(data_lowest); | |
| var g = svg.selectAll("svg").data(data_lowest).enter() | |
| g.selectAll("text").data(function(d) {return d}).enter() | |
| .append("text") | |
| .attr("x", 120) | |
| // Here is the Problem. I don't now how to elegant move elements in y direction | |
| // depending on previous elements. And also move following elements down. | |
| .attr("y", function(d,i) {return 100+i*20;}) | |
| .text(function(d, i) { | |
| console.log(i, d.values.toString()); | |
| return d.values.toString(); | |
| }) | |
| .attr("font-size", 24) | |
| .attr("font-family", "monospace"); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment