peitychart.init.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. (function($){
  2. "use strict"; // Start of use strict
  3. $(function() {
  4. "use strict";
  5. // Just the defaults.
  6. $("span.pie").peity("pie",{
  7. width: '50',
  8. height: '50'
  9. })
  10. $('span.donut').peity('donut',{
  11. width: '50',
  12. height: '50'
  13. })
  14. $(".peity-line").peity("line",{
  15. width: '100%',
  16. height: '100'
  17. })
  18. $(".bar").peity("bar",{
  19. width: '100%',
  20. height: '50'
  21. })
  22. $(".bar-colours-1").peity("bar", {
  23. fill: ["red", "green", "blue"],
  24. width: '100',
  25. height: '100'
  26. })
  27. $(".bar-colours-2").peity("bar", {
  28. fill: function(value) {
  29. return value > 0 ? "green" : "red"
  30. },
  31. width: '100',
  32. height: '100'
  33. })
  34. $(".bar-colours-3").peity("bar", {
  35. fill: function(_, i, all) {
  36. var g = parseInt((i / all.length) * 255)
  37. return "rgb(255, " + g + ", 0)"
  38. },
  39. width: '100',
  40. height: '100'
  41. })
  42. $(".pie-colours-1").peity("pie", {
  43. fill: ["cyan", "magenta", "yellow", "black"],
  44. width: '100',
  45. height: '100'
  46. })
  47. $(".pie-colours-2").peity("pie", {
  48. fill: function(_, i, all) {
  49. var g = parseInt((i / all.length) * 255)
  50. return "rgb(255, " + g + ", 0)"
  51. },
  52. width: '100',
  53. height: '100'
  54. })
  55. // Using data attributes
  56. $(".data-attributes span").peity("donut")
  57. // Evented example.
  58. $("select").change(function() {
  59. var text = $(this).val() + "/" + 5
  60. $(this)
  61. .siblings("span.graph")
  62. .text(text)
  63. .change()
  64. $("#notice").text("Chart updated: " + text)
  65. }).change()
  66. $("span.graph").peity("pie")
  67. // Updating charts.
  68. var updatingChart = $(".updating-chart").peity("line", { width: "100%",height:150 })
  69. setInterval(function() {
  70. var random = Math.round(Math.random() * 20)
  71. var values = updatingChart.text().split(",")
  72. values.shift()
  73. values.push(random)
  74. updatingChart
  75. .text(values.join(","))
  76. .change()
  77. }, 2500)
  78. })
  79. })(jQuery);