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.

chartlist-custom.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. "use strict";
  2. $(document).ready(function(){
  3. /*BI-POLAR LINE CHART WITH AREA ONLY*/
  4. new Chartist.Line('.ct-chart', {
  5. labels: [1, 2, 3, 4, 5, 6, 7, 8],
  6. series: [
  7. [1, 2, 3, 1, -2, 0, 1, 0],
  8. [-2, -1, -2, -1, -2.5, -1, -2, -1],
  9. [0, 0, 0, 1, 2, 2.5, 2, 1],
  10. [2.5, 2, 1, 0.5, 1, 0.5, -1, -2.5]
  11. ]
  12. }, {
  13. high: 3,
  14. low: -3,
  15. showArea: true,
  16. showLine: false,
  17. showPoint: false,
  18. fullWidth: true,
  19. axisX: {
  20. showLabel: true,
  21. showGrid: false
  22. }
  23. });
  24. /*Threshold plugin for Chartist start*/
  25. new Chartist.Line('.ct-chart1', {
  26. labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
  27. series: [
  28. [5, -4, 3, 7, 20, 10]
  29. ]
  30. }, {
  31. showArea: false,
  32. axisY: {
  33. onlyInteger: true
  34. },
  35. plugins: [
  36. Chartist.plugins.ctThreshold({
  37. threshold: 4
  38. })
  39. ]
  40. });
  41. var defaultOptions = {
  42. threshold: 0,
  43. classNames: {
  44. aboveThreshold: 'ct-threshold-above',
  45. belowThreshold: 'ct-threshold-below'
  46. },
  47. maskNames: {
  48. aboveThreshold: 'ct-threshold-mask-above',
  49. belowThreshold: 'ct-threshold-mask-below'
  50. }
  51. };
  52. /*ADVANCED SMIL ANIMATIONS*/
  53. var chart = new Chartist.Line('.ct-chart2', {
  54. labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
  55. series: [
  56. [12, 9, 7, 8, 5, 4, 6, 2, 3, 3, 4, 6],
  57. [4, 5, 3, 7, 3, 5, 5, 3, 4, 4, 5, 5],
  58. [5, 3, 4, 5, 6, 3, 3, 4, 5, 6, 3, 4],
  59. [3, 4, 5, 6, 7, 6, 4, 5, 6, 7, 6, 3]
  60. ]
  61. }, {
  62. low: 0
  63. });
  64. // Let's put a sequence number aside so we can use it in the event callbacks
  65. var seq = 0,
  66. delays = 80,
  67. durations = 500;
  68. // Once the chart is fully created we reset the sequence
  69. chart.on('created', function() {
  70. seq = 0;
  71. });
  72. // On each drawn element by Chartist we use the Chartist.Svg API to trigger SMIL animations
  73. chart.on('draw', function(data) {
  74. seq++;
  75. if(data.type === 'line') {
  76. // If the drawn element is a line we do a simple opacity fade in. This could also be achieved using CSS3 animations.
  77. data.element.animate({
  78. opacity: {
  79. // The delay when we like to start the animation
  80. begin: seq * delays + 1000,
  81. // Duration of the animation
  82. dur: durations,
  83. // The value where the animation should start
  84. from: 0,
  85. // The value where it should end
  86. to: 1
  87. }
  88. });
  89. } else if(data.type === 'label' && data.axis === 'x') {
  90. data.element.animate({
  91. y: {
  92. begin: seq * delays,
  93. dur: durations,
  94. from: data.y + 100,
  95. to: data.y,
  96. // We can specify an easing function from Chartist.Svg.Easing
  97. easing: 'easeOutQuart'
  98. }
  99. });
  100. } else if(data.type === 'label' && data.axis === 'y') {
  101. data.element.animate({
  102. x: {
  103. begin: seq * delays,
  104. dur: durations,
  105. from: data.x - 100,
  106. to: data.x,
  107. easing: 'easeOutQuart'
  108. }
  109. });
  110. } else if(data.type === 'point') {
  111. data.element.animate({
  112. x1: {
  113. begin: seq * delays,
  114. dur: durations,
  115. from: data.x - 10,
  116. to: data.x,
  117. easing: 'easeOutQuart'
  118. },
  119. x2: {
  120. begin: seq * delays,
  121. dur: durations,
  122. from: data.x - 10,
  123. to: data.x,
  124. easing: 'easeOutQuart'
  125. },
  126. opacity: {
  127. begin: seq * delays,
  128. dur: durations,
  129. from: 0,
  130. to: 1,
  131. easing: 'easeOutQuart'
  132. }
  133. });
  134. } else if(data.type === 'grid') {
  135. // Using data.axis we get x or y which we can use to construct our animation definition objects
  136. var pos1Animation = {
  137. begin: seq * delays,
  138. dur: durations,
  139. from: data[data.axis.units.pos + '1'] - 30,
  140. to: data[data.axis.units.pos + '1'],
  141. easing: 'easeOutQuart'
  142. };
  143. var pos2Animation = {
  144. begin: seq * delays,
  145. dur: durations,
  146. from: data[data.axis.units.pos + '2'] - 100,
  147. to: data[data.axis.units.pos + '2'],
  148. easing: 'easeOutQuart'
  149. };
  150. var animations = {};
  151. animations[data.axis.units.pos + '1'] = pos1Animation;
  152. animations[data.axis.units.pos + '2'] = pos2Animation;
  153. animations['opacity'] = {
  154. begin: seq * delays,
  155. dur: durations,
  156. from: 0,
  157. to: 1,
  158. easing: 'easeOutQuart'
  159. };
  160. data.element.animate(animations);
  161. }
  162. });
  163. // For the sake of the example we update the chart every time it's created with a delay of 10 seconds
  164. chart.on('created', function() {
  165. if(window.__exampleAnimateTimeout) {
  166. clearTimeout(window.__exampleAnimateTimeout);
  167. window.__exampleAnimateTimeout = null;
  168. }
  169. window.__exampleAnimateTimeout = setTimeout(chart.update.bind(chart), 12000);
  170. });
  171. /*GAUGE CHART*/
  172. new Chartist.Pie('.ct-chart3', {
  173. series: [20, 10, 30, 40]
  174. },
  175. {
  176. donut: true,
  177. donutWidth: 60,
  178. startAngle: 270,
  179. total: 200,
  180. showLabel: false
  181. });
  182. //HORIZONTAL BAR CHART
  183. new Chartist.Bar('.ct-chart-horizontal', {
  184. labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
  185. series: [
  186. [5, 4, 3, 7, 5, 10, 3],
  187. [3, 2, 9, 5, 4, 6, 4]
  188. ]
  189. }, {
  190. seriesBarDistance: 10,
  191. reverseData: true,
  192. horizontalBars: true,
  193. axisY: {
  194. offset: 70
  195. }
  196. });
  197. // ANIMATING A DONUT WITH SVG.ANIMATE Start
  198. var chart = new Chartist.Pie('.ct-chart-animating', {
  199. series: [10, 20, 50, 20, 5, 50, 15],
  200. labels: [1, 2, 3, 4, 5, 6, 7]
  201. }, {
  202. donut: true,
  203. showLabel: false
  204. });
  205. chart.on('draw', function(data) {
  206. if(data.type === 'slice') {
  207. // Get the total path length in order to use for dash array animation
  208. var pathLength = data.element._node.getTotalLength();
  209. // Set a dasharray that matches the path length as prerequisite to animate dashoffset
  210. data.element.attr({
  211. 'stroke-dasharray': pathLength + 'px ' + pathLength + 'px'
  212. });
  213. // Create animation definition while also assigning an ID to the animation for later sync usage
  214. var animationDefinition = {
  215. 'stroke-dashoffset': {
  216. id: 'anim' + data.index,
  217. dur: 800,
  218. from: -pathLength + 'px',
  219. to: '0px',
  220. easing: Chartist.Svg.Easing.easeOutQuint,
  221. // We need to use `fill: 'freeze'` otherwise our animation will fall back to initial (not visible)
  222. fill: 'freeze'
  223. }
  224. };
  225. // If this was not the first slice, we need to time the animation so that it uses the end sync event of the previous animation
  226. if(data.index !== 0) {
  227. animationDefinition['stroke-dashoffset'].begin = 'anim' + (data.index - 1) + '.end';
  228. }
  229. // We need to set an initial value before the animation starts as we are not in guided mode which would do that for us
  230. data.element.attr({
  231. 'stroke-dashoffset': -pathLength + 'px'
  232. });
  233. // We can't use guided mode as the animations need to rely on setting begin manually
  234. // See http://gionkunz.github.io/chartist-js/api-documentation.html#chartistsvg-function-animate
  235. data.element.animate(animationDefinition, false);
  236. }
  237. });
  238. // For the sake of the example we update the chart every time it's created with a delay of 8 seconds
  239. chart.on('created', function() {
  240. if(window.__anim21278907124) {
  241. clearTimeout(window.__anim21278907124);
  242. window.__anim21278907124 = null;
  243. }
  244. window.__anim21278907124 = setTimeout(chart.update.bind(chart), 10000);
  245. });
  246. //ADD PEAK CIRCLES USING THE DRAW
  247. // Create a simple bi-polar bar chart
  248. var chart = new Chartist.Bar('.ct-chart-add-pack', {
  249. labels: ['W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'W10'],
  250. series: [
  251. [1, 2, 4, 8, 6, -2, -1, -4, -6, -2]
  252. ]
  253. }, {
  254. high: 10,
  255. low: -10,
  256. axisX: {
  257. labelInterpolationFnc: function(value, index) {
  258. return index % 2 === 0 ? value : null;
  259. }
  260. }
  261. });
  262. // Listen for draw events on the bar chart
  263. chart.on('draw', function(data) {
  264. // If this draw event is of type bar we can use the data to create additional content
  265. if(data.type === 'bar') {
  266. // We use the group element of the current series to append a simple circle with the bar peek coordinates and a circle radius that is depending on the value
  267. data.group.append(new Chartist.Svg('circle', {
  268. cx: data.x2,
  269. cy: data.y2,
  270. r: Math.abs(Chartist.getMultiValue(data.value)) * 2 + 5
  271. }, 'ct-slice-pie'));
  272. }
  273. });
  274. //series overrids
  275. var chart = new Chartist.Line('.ct-chart-overrides', {
  276. labels: ['1', '2', '3', '4', '5', '6', '7', '8'],
  277. // Naming the series with the series object array notation
  278. series: [{
  279. name: 'series-1',
  280. data: [5, 2, -4, 2, 0, -2, 5, -3]
  281. }, {
  282. name: 'series-2',
  283. data: [4, 3, 5, 3, 1, 3, 6, 4]
  284. }, {
  285. name: 'series-3',
  286. data: [2, 4, 3, 1, 4, 5, 3, 2]
  287. }]
  288. }, {
  289. fullWidth: true,
  290. // Within the series options you can use the series names
  291. // to specify configuration that will only be used for the
  292. // specific series.
  293. series: {
  294. 'series-1': {
  295. lineSmooth: Chartist.Interpolation.step()
  296. },
  297. 'series-2': {
  298. lineSmooth: Chartist.Interpolation.simple(),
  299. showArea: true
  300. },
  301. 'series-3': {
  302. showPoint: false
  303. }
  304. }
  305. }, [
  306. // You can even use responsive configuration overrides to
  307. // customize your series configuration even further!
  308. ['screen and (max-width: 320px)', {
  309. series: {
  310. 'series-1': {
  311. lineSmooth: Chartist.Interpolation.none()
  312. },
  313. 'series-2': {
  314. lineSmooth: Chartist.Interpolation.none(),
  315. showArea: false
  316. },
  317. 'series-3': {
  318. lineSmooth: Chartist.Interpolation.none(),
  319. showPoint: true
  320. }
  321. }
  322. }]
  323. ]);
  324. });