piegage-demo.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Pie gauges */
  2. var initPieChart = function() {
  3. $('.chart').easyPieChart({
  4. barColor: function(percent) {
  5. percent /= 100;
  6. return "rgb(" + Math.round(254 * (1 - percent)) + ", " + Math.round(255 * percent) + ", 0)";
  7. },
  8. animate: 1000,
  9. scaleColor: '#ccc',
  10. lineWidth: 3,
  11. size: 100,
  12. lineCap: 'cap',
  13. onStep: function(value) {
  14. this.$el.find('span').text(~~value);
  15. }
  16. });
  17. $('.chart-home').easyPieChart({
  18. barColor: 'rgba(255,255,255,0.5)',
  19. trackColor: 'rgba(255,255,255,0.1)',
  20. animate: 1000,
  21. scaleColor: 'rgba(255,255,255,0.3)',
  22. lineWidth: 3,
  23. size: 100,
  24. lineCap: 'cap',
  25. onStep: function(value) {
  26. this.$el.find('span').text(~~value);
  27. }
  28. });
  29. $('.chart-alt').easyPieChart({
  30. barColor: function(percent) {
  31. percent /= 100;
  32. return "rgb(" + Math.round(255 * (1 - percent)) + ", " + Math.round(255 * percent) + ", 0)";
  33. },
  34. trackColor: '#333',
  35. scaleColor: false,
  36. lineCap: 'butt',
  37. rotate: -90,
  38. lineWidth: 20,
  39. animate: 1500,
  40. onStep: function(value) {
  41. this.$el.find('span').text(~~value);
  42. }
  43. });
  44. $('.chart-alt-1').easyPieChart({
  45. barColor: function(percent) {
  46. percent /= 100;
  47. return "rgb(" + Math.round(255 * (1 - percent)) + ", " + Math.round(255 * percent) + ", 0)";
  48. },
  49. trackColor: '#e1ecf1',
  50. scaleColor: '#c4d7e0',
  51. lineCap: 'cap',
  52. rotate: -90,
  53. lineWidth: 10,
  54. size: 80,
  55. animate: 2500,
  56. onStep: function(value) {
  57. this.$el.find('span').text(~~value);
  58. }
  59. });
  60. $('.chart-alt-2').easyPieChart({
  61. barColor: function(percent) {
  62. percent /= 100;
  63. return "rgb(" + Math.round(255 * (1 - percent)) + ", " + Math.round(255 * percent) + ", 0)";
  64. },
  65. trackColor: '#fff',
  66. scaleColor: false,
  67. lineCap: 'butt',
  68. rotate: -90,
  69. lineWidth: 4,
  70. size: 50,
  71. animate: 1500,
  72. onStep: function(value) {
  73. this.$el.find('span').text(~~value);
  74. }
  75. });
  76. $('.chart-alt-3').easyPieChart({
  77. barColor: function(percent) {
  78. percent /= 100;
  79. return "rgb(" + Math.round(255 * (1 - percent)) + ", " + Math.round(255 * percent) + ", 0)";
  80. },
  81. trackColor: '#333',
  82. scaleColor: true,
  83. lineCap: 'butt',
  84. rotate: -90,
  85. lineWidth: 4,
  86. size: 50,
  87. animate: 1500,
  88. onStep: function(value) {
  89. this.$el.find('span').text(~~value);
  90. }
  91. });
  92. $('.chart-alt-10').easyPieChart({
  93. barColor: 'rgba(255,255,255,255.4)',
  94. trackColor: 'rgba(255,255,255,0.1)',
  95. scaleColor: 'transparent',
  96. lineCap: 'round',
  97. rotate: -90,
  98. lineWidth: 4,
  99. size: 100,
  100. animate: 2500,
  101. onStep: function(value) {
  102. this.$el.find('span').text(~~value);
  103. }
  104. });
  105. $('.updateEasyPieChart').on('click', function(e) {
  106. e.preventDefault();
  107. $('.chart-home, .chart, .chart-alt, .chart-alt-1, .chart-alt-2, .chart-alt-3, .chart-alt-10').each(function() {
  108. $(this).data('easyPieChart').update(Math.round(100 * Math.random()));
  109. });
  110. });
  111. };
  112. $(document).ready(function() {
  113. initPieChart();
  114. });