Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. initPieChart: function (id, title, sub, footer, values, labelOrQtd){
  2.  
  3. var dataPieChart = {
  4. series: [160, 60],
  5. labels: ['', '']
  6. };
  7.  
  8. var optionsPieChart = {
  9. donut: true,
  10. donutWidth: 20,
  11. startAngle: 210,
  12. total: 260,
  13. showLabel: false,
  14. plugins: [
  15. [
  16. Chartist.plugins.fillDonut({
  17. items: [{
  18. content: '<i class="fa fa-tachometer text-muted"></i>',
  19. position: 'bottom',
  20. offsetY: 10,
  21. offsetX: -2
  22. }, {
  23. content: '<h3>80<span class="small">%</span></h3>'
  24. }]
  25. })
  26. ]
  27. ]
  28. };
  29.  
  30. var end = '#' + id;
  31. var pieChart = new Chartist.Pie(end, dataPieChart, optionsPieChart);
  32.  
  33. //start animation for the Bar Chart
  34. md.startAnimationForPieChart(pieChart);
  35. }
  36.  
  37. startAnimationForPieChart: function (chart) {
  38.  
  39. chart.on('draw', function (data) {
  40. if (data.type === 'slice' && data.index == 0) {
  41. // Get the total path length in order to use for dash array animation
  42. var pathLength = data.element._node.getTotalLength();
  43.  
  44.  
  45. // Set a dasharray that matches the path length as prerequisite to animate dashoffset
  46. data.element.attr({
  47. 'stroke-dasharray': pathLength + 'px ' + pathLength + 'px'
  48. });
  49.  
  50. // Create animation definition while also assigning an ID to the animation for later sync usage
  51. var animationDefinition = {
  52. 'stroke-dashoffset': {
  53. id: 'anim' + data.index,
  54. dur: 1200,
  55. from: -pathLength + 'px',
  56. to: '0px',
  57. easing: Chartist.Svg.Easing.easeOutQuint,
  58. // We need to use `fill: 'freeze'` otherwise our animation will fall back to initial (not visible)
  59. fill: 'freeze'
  60. }
  61. };
  62.  
  63. // We need to set an initial value before the animation starts as we are not in guided mode which would do that for us
  64. data.element.attr({
  65. 'stroke-dashoffset': -pathLength + 'px'
  66. });
  67.  
  68. // We can't use guided mode as the animations need to rely on setting begin manually
  69. // See http://gionkunz.github.io/chartist-js/api-documentation.html#chartistsvg-function-animate
  70. data.element.animate(animationDefinition, true);
  71. }
  72. });
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement