Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chart-nvd3.js 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. "use strict";
  2. $(document).ready(function() {
  3. /*Line chart start*/
  4. /*These lines are all chart setup. Pick and choose which chart features you want to utilize. */
  5. nv.addGraph(function() {
  6. var chart = nv.models.lineChart()
  7. .margin({ top: 50 })
  8. .margin({ left: 100 }) //Adjust chart margins to give the x-axis some breathing room.
  9. .useInteractiveGuideline(true) //We want nice looking tooltips and a guideline!
  10. .showLegend(true) //Show the legend, allowing users to turn on/off line series.
  11. .showYAxis(true) //Show the y-axis
  12. .showXAxis(true) //Show the x-axis
  13. ;
  14. chart.xAxis //Chart x-axis settings
  15. .axisLabel('Time (ms)')
  16. .tickFormat(d3.format(',r'));
  17. chart.yAxis //Chart y-axis settings
  18. .axisLabel('Voltage (v)')
  19. .tickFormat(d3.format('.02f'));
  20. /* Done setting the chart up? Time to render it!*/
  21. var myData = sinAndCos(); //You need data...
  22. d3.select('#linechart').append('svg') //Select the <svg> element you want to render the chart in.
  23. .datum(myData) //Populate the <svg> element with chart data...
  24. .call(chart); //Finally, render the chart!
  25. //Update the chart when window resizes.
  26. nv.utils.windowResize(function() { chart.update() });
  27. return chart;
  28. });
  29. /**************************************
  30. * Simple test data generator
  31. */
  32. function sinAndCos() {
  33. var sin = [],
  34. sin2 = [],
  35. cos = [];
  36. //Data is represented as an array of {x,y} pairs.
  37. for (var i = 0; i < 100; i++) {
  38. sin.push({ x: i, y: Math.sin(i / 10) });
  39. sin2.push({ x: i, y: Math.sin(i / 10) * 0.25 + 0.5 });
  40. cos.push({ x: i, y: .5 * Math.cos(i / 10) });
  41. }
  42. //Line chart data should be sent as an array of series objects.
  43. return [{
  44. values: sin, //values - represents the array of {x,y} data points
  45. key: 'Sine Wave', //key - the name of the series.
  46. color: '#4C5667' //color - optional: choose your own line color.
  47. }, {
  48. values: cos,
  49. key: 'Cosine Wave',
  50. color: '#11c15b'
  51. }, {
  52. values: sin2,
  53. key: 'Another sine wave',
  54. color: '#ff5252',
  55. area: true //area - set to true if you want this line to turn into a filled area chart.
  56. }];
  57. }
  58. /*Bar chart start*/
  59. nv.addGraph(function() {
  60. var chart = nv.models.discreteBarChart()
  61. .x(function(d) {
  62. return d.label }) //Specify the data accessors.
  63. .y(function(d) {
  64. return d.value })
  65. .staggerLabels(true) //Too many bars and not enough room? Try staggering labels.
  66. /* .tooltips(false) */ //Don't show tooltips
  67. .showValues(true) //...instead, show the bar value right on top of each bar.
  68. /* .transitionDuration(350)*/
  69. ;
  70. d3.select('#barchart').append('svg')
  71. .datum(barData())
  72. .call(chart);
  73. nv.utils.windowResize(chart.update);
  74. return chart;
  75. });
  76. //Each bar represents a single discrete quantity.
  77. function barData() {
  78. return [{
  79. key: "Cumulative Return",
  80. values: [{
  81. "label": "A",
  82. "value": -29.765957771107,
  83. "color": "#FF9F55"
  84. }, {
  85. "label": "B",
  86. "value": 10,
  87. "color": "#FEC811"
  88. }, {
  89. "label": "C",
  90. "value": 32.807804682612,
  91. "color": "#4C5667"
  92. }, {
  93. "label": "D",
  94. "value": 196.45946739256,
  95. "color": "#01C0C8"
  96. }, {
  97. "label": "E",
  98. "value": 0.25434030906893,
  99. "color": "#FF0084"
  100. }, {
  101. "label": "F",
  102. "value": -98.079782601442,
  103. "color": "#007BB6"
  104. }, {
  105. "label": "G",
  106. "value": -13.925743130903,
  107. "color": "#3b5998"
  108. }, {
  109. "label": "H",
  110. "value": -5.1387322875705,
  111. "color": "#B2E0A2"
  112. }]
  113. }]
  114. }
  115. /*Scatter chart start*/
  116. nv.addGraph(function() {
  117. var chart = nv.models.scatterChart()
  118. .showDistX(true) //showDist, when true, will display those little distribution lines on the axis.
  119. .showDistY(true)
  120. /* .transitionDuration(350)*/
  121. .color(d3.scale.category10().range());
  122. //Configure how the tooltip looks.
  123. /* chart.tooltipContent(function(key) {
  124. return '<h3>' + key + '</h3>';
  125. });*/
  126. //Axis settings
  127. chart.xAxis.tickFormat(d3.format('.02f'));
  128. chart.yAxis.tickFormat(d3.format('.02f'));
  129. //We want to show shapes other than circles.
  130. /*chart.scatter.onlyCircles(false);*/
  131. var myData = randomData(4, 40);
  132. d3.select('#scatterchart').append('svg')
  133. .datum(myData)
  134. .call(chart);
  135. nv.utils.windowResize(chart.update);
  136. return chart;
  137. });
  138. /**************************************
  139. * Simple test data generator
  140. */
  141. function randomData(groups, points) { //# groups,# points per group
  142. var data = [],
  143. shapes = ['circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'],
  144. random = d3.random.normal();
  145. for (var i = 0; i < groups; i++) {
  146. data.push({
  147. key: 'Group ' + i,
  148. values: []
  149. });
  150. for (var j = 0; j < points; j++) {
  151. data[i].values.push({
  152. x: random(),
  153. y: random(),
  154. size: Math.random() //Configure the size of each scatter point
  155. ,
  156. shape: (Math.random() > 0.95) ? shapes[j % 6] : "circle" //Configure the shape of each scatter point.
  157. });
  158. }
  159. }
  160. return data;
  161. }
  162. /*Stacked/Group chart start*/
  163. nv.addGraph(function() {
  164. var chart = nv.models.multiBarChart()
  165. /* .transitionDuration(350)*/
  166. .reduceXTicks(true) //If 'false', every single x-axis tick label will be rendered.
  167. .rotateLabels(0) //Angle to rotate x-axis labels.
  168. .showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
  169. .groupSpacing(0.1) //Distance between each group of bars.
  170. ;
  171. chart.xAxis
  172. .tickFormat(d3.format(',f'));
  173. chart.yAxis
  174. .tickFormat(d3.format(',.1f'));
  175. d3.select('#stackedchart').append('svg')
  176. .datum(stackedData())
  177. .call(chart);
  178. nv.utils.windowResize(chart.update);
  179. return chart;
  180. });
  181. //Generate some nice data.
  182. function stackedData() {
  183. return stream_layers(3, 10 + Math.random() * 100, .1).map(function(data, i) {
  184. return {
  185. key: 'Stream #' + i,
  186. values: data
  187. };
  188. });
  189. }
  190. /*Regular Pie chart*/
  191. nv.addGraph(function() {
  192. var chart = nv.models.pieChart()
  193. .x(function(d) {
  194. return d.label })
  195. .y(function(d) {
  196. return d.value })
  197. .showLabels(true);
  198. d3.select("#piechart").append('svg')
  199. .datum(pieData())
  200. .transition().duration(350)
  201. .call(chart);
  202. nv.utils.windowResize(chart.update);
  203. return chart;
  204. });
  205. //Donut chart example
  206. nv.addGraph(function() {
  207. var chart = nv.models.pieChart()
  208. .x(function(d) {
  209. return d.label })
  210. .y(function(d) {
  211. return d.value })
  212. .showLabels(true) //Display pie labels
  213. .labelThreshold(.05) //Configure the minimum slice size for labels to show up
  214. .labelType("percent") //Configure what type of data to show in the label. Can be "key", "value" or "percent"
  215. .donut(true) //Turn on Donut mode. Makes pie chart look tasty!
  216. .donutRatio(0.35) //Configure how big you want the donut hole size to be.
  217. ;
  218. d3.select("#donutchart").append('svg')
  219. .datum(pieData())
  220. .transition().duration(350)
  221. .call(chart);
  222. nv.utils.windowResize(chart.update);
  223. return chart;
  224. });
  225. //Pie chart example data. Note how there is only a single array of key-value pairs.
  226. function pieData() {
  227. return [{
  228. "label": "One",
  229. "value": 29.765957771107,
  230. "color": "#FB9678"
  231. }, {
  232. "label": "Two",
  233. "value": 0,
  234. "color": "#FF9F55"
  235. }, {
  236. "label": "Three",
  237. "value": 32.807804682612,
  238. "color": "#01C0C8"
  239. }, {
  240. "label": "Four",
  241. "value": 196.45946739256,
  242. "color": "#00C292"
  243. }, {
  244. "label": "Five",
  245. "value": 0.19434030906893,
  246. "color": "#4F5467"
  247. }, {
  248. "label": "Six",
  249. "value": 98.079782601442,
  250. "color": "#4F5467"
  251. }, {
  252. "label": "Seven",
  253. "value": 13.925743130903,
  254. "color": "#000000"
  255. }, {
  256. "label": "Eight",
  257. "value": 5.1387322875705,
  258. "color": "#CB2027"
  259. }];
  260. }
  261. });