Guest User

Untitled

a guest
Oct 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <button id="btn1">Sobreviventes e mortos por grupos</button>
  2. <button id="btn2">Sobreviventes e mortos por porta de embarque</button>
  3. <button id="btn3">Foto</button>
  4.  
  5.  
  6. <div id="chartContainer">
  7.  
  8. <script type="text/javascript">
  9.  
  10. // novo gráfio bubble incluso
  11.  
  12. var svg = dimple.newSvg("#chartContainer", 590, 400);
  13. d3.csv("d3_1.csv", function (data) {
  14. var myChart = new dimple.chart(svg, data);
  15. myChart.setBounds(65, 30, 505, 330)
  16. myChart.addCategoryAxis("x", ["Embarked", "Survived"]);
  17. myChart.addMeasureAxis("y", "Amount");
  18. myChart.addMeasureAxis("z", "Amount");
  19. myChart.addSeries("Survived", dimple.plot.bubble);
  20. myChart.addLegend(70, 10, 510, 20, "right");
  21. myChart.draw();
  22. });
  23. </script>
  24.  
  25. <script type="text/javascript">
  26.  
  27. d3.select("#btn1").on("click", function(){
  28. d3.select("svg").remove();
  29. var svg = dimple.newSvg("#chartContainer", 590, 400);
  30. d3.csv("d3_1.csv", function (data) {
  31. var myChart = new dimple.chart(svg, data);
  32. myChart.setBounds(65, 30, 505, 330)
  33. myChart.addCategoryAxis("x", ["Embarked", "Survived"]);
  34. myChart.addMeasureAxis("y", "Amount");
  35. myChart.addMeasureAxis("z", "Amount");
  36. myChart.addSeries("Survived", dimple.plot.bubble);
  37. myChart.addLegend(70, 10, 510, 20, "right");
  38. myChart.draw();
  39. });
  40. });
  41. </script>
  42.  
  43. <script type="text/javascript">
  44.  
  45. d3.select("#btn2").on("click", function(){
  46. d3.select("svg").remove();
  47. var svg = dimple.newSvg("#chartContainer", 600, 400);
  48. d3.csv("d3_1.csv", function (data) {
  49. var myChart = new dimple.chart(svg, data);
  50. myChart.setBounds(80, 30, 480, 330)
  51. myChart.addMeasureAxis("x", "Amount");
  52. myChart.addCategoryAxis("y", ["Embarked", "Survived"]);
  53. myChart.addSeries("Survived", dimple.plot.bar);
  54. myChart.addLegend(60, 10, 510, 20, "right");
  55. myChart.draw();
  56.  
  57. });
  58. });
  59. </script>
  60.  
  61. <script>
  62.  
  63. d3.select("#btn3").on("click", function(){
  64. // Fazer com que a OPÇÃO 1 ou 2 abaixo funcione com o botão acima exibindo a imagem
  65. do link: http://svgur.com/i/3Wh.svg
  66.  
  67.  
  68. });
  69. });
  70. </script>
  71.  
  72. OPÇÃO 1
  73. d3.xml("rect01.svg").mimeType("image/svg+xml").get(function(error, xml) {
  74. if (error) throw error;
  75. document.body.appendChild(xml.documentElement);
  76. });
  77.  
  78. OPÇÃO 2
  79.  
  80. d3.xml("/assets/infographics/" + svgSource, "image/svg+xml", function(xml) {
  81. var importedNode = document.importNode(xml.documentElement, true);
  82.  
  83. $('#svg-image')
  84. .find('g#' + id).append($(xml.documentElement).clone());
  85. container.attr("x" , "200px");
  86. container.attr("y", "200px");
  87. });
  88.  
  89. fonte: http://blog.optimal.io/how-to-add-a-svg-image-in-d3/
Add Comment
Please, Sign In to add comment