Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <title>D3: SVG pie chart </title>
  7. <script type="text/javascript" src="../d3.js"></script>
  8. <style type="text/css">
  9. /* No style rules here yet */
  10. #svg {
  11. background: #f00;
  12. ;
  13. }
  14.  
  15. .text {
  16. font-family: Arial, Helvetica, sans-serif;
  17. fill: #fff;
  18. font-size: 1em;
  19. text-anchor: middle;
  20. }
  21.  
  22. .zetels {
  23. font-weight: 900;
  24. }
  25.  
  26. .partij {
  27. text-transform: uppercase;
  28. font-weight: 300;
  29. }
  30.  
  31. .NV-A {
  32. fill: rgb(250, 221, 0);
  33. }
  34.  
  35. .PS,
  36. .sp-a {
  37.  
  38. fill: rgb(255, 0, 20);
  39. }
  40.  
  41. .VlaamsBelang {
  42. fill: rgb(225, 174, 31);
  43. }
  44.  
  45. .CDV,
  46. .CDH {
  47. fill: rgb(255, 128, 0);
  48. }
  49.  
  50. .MR,
  51. .Open-VLD {
  52. fill: rgb(29, 78, 182);
  53. }
  54.  
  55. .Ecolo,
  56. .groen {
  57. fill: rgb(0, 163, 160)
  58. }
  59.  
  60. .PTB-PVDA {
  61. fill: rgb(204, 0, 68)
  62. }
  63.  
  64. .DeFi {
  65. fill: rgb(203, 0, 173);
  66. }
  67.  
  68. ;
  69. </style>
  70. <div id="my_dataviz"></div>
  71. </head>
  72.  
  73. <body>
  74. <script type="text/javascript">
  75. //Half pie chart
  76.  
  77. //Settings
  78. var width = 600
  79. var height = 300
  80. //var margin = 40
  81. var anglesRange = 0.5 * Math.PI
  82. //var radius = Math.min(width, 2 * height) / 2
  83. var radius = Math.min(width, 2 * height) / 2
  84.  
  85. var thickness = 20
  86.  
  87. //Data
  88. d3.csv('./federaal.csv', function (data) {
  89. dataset = data;
  90. console.log(dataset);
  91. init();
  92. });
  93.  
  94. function init() {
  95. // The radius of the pieplot is half the width or half the height (smallest one). I subtract a bit of margin.
  96. //var radius = Math.min(width, height) / margin
  97.  
  98. // append the svg object to the div called 'my_dataviz'
  99. var svg = d3.select("#my_dataviz")
  100. .append("svg")
  101. .attr("width", width)
  102. .attr("height", height)
  103. .append("g")
  104. .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
  105.  
  106. //Create dummy data
  107. // var data = {
  108. // a: 9,
  109. // b: 20
  110. // }
  111.  
  112. // set the color scale
  113. var color = d3.scaleOrdinal()
  114. .domain(dataset)
  115. .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56"])
  116.  
  117. // Compute the position of each group on the pie:
  118. var pie = d3.pie()
  119. .value(function (d) {
  120. return d.value.Zetels;
  121. })
  122. .startAngle(anglesRange * -1)
  123. .endAngle(anglesRange)
  124. var data_ready = pie(d3.entries(dataset))
  125.  
  126. // Build the pie chart: Basically, each part of the pie is a path that we build using the arc function.
  127. svg
  128. .selectAll('whatever')
  129. .data(data_ready)
  130. .enter()
  131. .append('path')
  132. .attr('d', d3.arc()
  133. .innerRadius(100) // This is the size of the donut hole
  134. .outerRadius(20)
  135. )
  136. .attr("class", function (d) {
  137. //var partij = d.Partij.replace(/\s/g, '');
  138. console.log("d console: ", d.data)
  139. return 'bar ' + d.data.value.Partij;
  140. })
  141. .attr("stroke", "white")
  142. .style("stroke-width", "2px")
  143. .style("opacity", 0.7)
  144.  
  145.  
  146. }
  147. </script>
  148. </body>
  149.  
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement