Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. function renderGraphicForTraffic($container, data, timestampBack, timestampNow, dataPointsLabelsFormat, aggregatedEvery) {
  2.  
  3. var dataPointsInfo = [],
  4. dataPointsLabels = [];
  5.  
  6. var sortedByUnixTime = sortByUnixTimestamp(data.total_bytes);
  7.  
  8. //Loop through ajax requested data and prepare for the graph
  9.  
  10. $.each(sortedByUnixTime, function (currentIndex, currentValue) {
  11.  
  12. if (currentValue.time >= timestampBack && currentValue.time <= timestampNow && currentValue.time <=
  13. convertDateToTimestamp(new Date())) {
  14.  
  15. //Fill the array for drawing the graphic
  16. dataPointsInfo.push(currentValue.xAxis / (60 * aggregatedEvery)); // We delete by 60 * 5 because we got it every 5 mins
  17.  
  18. dataPointsLabels.push(moment(new Date(currentValue.time * 1000)).format(dataPointsLabelsFormat));
  19. }
  20. });
  21.  
  22. //Fill chart if there are dataPointsInfo and dataPointsLabels
  23.  
  24. if (dataPointsInfo.length && dataPointsLabels.length) {
  25.  
  26. $container = resetCanvas($container, $scope.trafficChart);
  27.  
  28. //Draw chart using Highcharts
  29.  
  30. $scope.trafficChart = Highcharts.chart({
  31. chart: {
  32. renderTo: $container,
  33. zoomType: 'x'
  34. },
  35. title: {
  36. text: 'Bandwidth'
  37. },
  38. subtitle: {
  39. text: document.ontouchstart === undefined ?
  40. 'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
  41. },
  42. xAxis: {
  43. categories: dataPointsLabels
  44. },
  45. yAxis: {
  46. title: {
  47. text: 'Mbps'
  48. }
  49. },
  50. legend: {
  51. enabled: false
  52. },
  53. plotOptions: {
  54. area: {
  55. fillColor: {
  56. linearGradient: {
  57. x1: 0,
  58. y1: 0,
  59. x2: 0,
  60. y2: 1
  61. },
  62. stops: [
  63. [0, Highcharts.getOptions().colors[0]],
  64. [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
  65. ]
  66. },
  67. marker: {
  68. radius: 2
  69. },
  70. lineWidth: 1,
  71. states: {
  72. hover: {
  73. lineWidth: 1
  74. }
  75. },
  76. threshold: null
  77. }
  78. },
  79.  
  80. series: [{
  81. type: 'area',
  82. name: 'Traffic',
  83. data: dataPointsInfo
  84. }]
  85. });
  86. }
  87.  
  88.  
  89. // //Draw chart using chart.js
  90. // $scope.trafficChart = new Chart($container, {
  91. // type: 'line',
  92. // data: {
  93. // labels: dataPointsLabels,
  94. // datasets: [{
  95. // label: 'Bandwidth',
  96. // data: dataPointsInfo,
  97. // fill: false,
  98. // lineTension: 0.3,
  99. // backgroundColor: "rgba(75,192,192,0.4)",
  100. // borderColor: "lightblue",
  101. // borderCapStyle: 'butt',
  102. // borderDash: [],
  103. // borderDashOffset: 0.0,
  104. // borderJoinStyle: 'round',
  105. // pointBorderColor: "rgba(75,192,192,1)",
  106. // pointBackgroundColor: "#fff",
  107. // pointBorderWidth: 1,
  108. // pointHoverRadius: 5,
  109. // pointHoverBackgroundColor: "rgba(75,192,192,1)",
  110. // pointHoverBorderColor: "rgba(220,220,220,1)",
  111. // pointHoverBorderWidth: 2,
  112. // pointRadius: 1,
  113. // pointHitRadius: 10,
  114. // }]
  115. // },
  116. // options: {
  117. // responsive: false,
  118. // scales: {
  119. // yAxes: [{
  120. // ticks: {
  121. // userCallback: function (data) {
  122. // return ((data * 8) / 1000000).toFixed(4) + ' Mbps';
  123. // }
  124. // },
  125. // // scaleLabel: {
  126. // // display: true,
  127. // // labelString: 'Mbps'
  128. // // }
  129.  
  130. // }]
  131. // },
  132. // tooltips: {
  133. // callbacks: {
  134. // label: function (tooltipItem, data) {
  135. // return ((data.datasets[0].data[tooltipItem.index] * 8) / 1000000).toFixed(4) + ' Mbps';
  136. // }
  137. // }
  138. // }
  139. // }
  140. // });
  141. // }
  142. else {
  143. noDataFoundErrorMsg($scope.trafficChartContainer, 'Sorry, no data for the selected period');
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement