morris.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. $(function () {
  2. getMorris('line', 'line_chart');
  3. getMorris('bar', 'bar_chart');
  4. getMorris('area', 'area_chart');
  5. getMorris('donut', 'donut_chart');
  6. });
  7. function getMorris(type, element) {
  8. if (type === 'line') {
  9. Morris.Line({
  10. element: element,
  11. data: [{
  12. 'period': '2011 Q3',
  13. 'licensed': 3407,
  14. 'sorned': 660
  15. }, {
  16. 'period': '2011 Q2',
  17. 'licensed': 3351,
  18. 'sorned': 629
  19. }, {
  20. 'period': '2011 Q1',
  21. 'licensed': 3269,
  22. 'sorned': 618
  23. }, {
  24. 'period': '2010 Q4',
  25. 'licensed': 3246,
  26. 'sorned': 661
  27. }, {
  28. 'period': '2009 Q4',
  29. 'licensed': 3171,
  30. 'sorned': 676
  31. }, {
  32. 'period': '2008 Q4',
  33. 'licensed': 3155,
  34. 'sorned': 681
  35. }, {
  36. 'period': '2007 Q4',
  37. 'licensed': 3226,
  38. 'sorned': 620
  39. }, {
  40. 'period': '2006 Q4',
  41. 'licensed': 3245,
  42. 'sorned': null
  43. }, {
  44. 'period': '2005 Q4',
  45. 'licensed': 3289,
  46. 'sorned': null
  47. }],
  48. xkey: 'period',
  49. ykeys: ['licensed', 'sorned'],
  50. labels: ['Licensed', 'Off the road'],
  51. lineColors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)'],
  52. lineWidth: 3
  53. });
  54. } else if (type === 'bar') {
  55. Morris.Bar({
  56. element: element,
  57. data: [{
  58. x: '2011 Q1',
  59. y: 3,
  60. z: 2,
  61. a: 3
  62. }, {
  63. x: '2011 Q2',
  64. y: 2,
  65. z: null,
  66. a: 1
  67. }, {
  68. x: '2011 Q3',
  69. y: 0,
  70. z: 2,
  71. a: 4
  72. }, {
  73. x: '2011 Q4',
  74. y: 2,
  75. z: 4,
  76. a: 3
  77. }],
  78. xkey: 'x',
  79. ykeys: ['y', 'z', 'a'],
  80. labels: ['Y', 'Z', 'A'],
  81. barColors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(0, 150, 136)'],
  82. });
  83. } else if (type === 'area') {
  84. Morris.Area({
  85. element: element,
  86. data: [{
  87. period: '2010 Q1',
  88. iphone: 2666,
  89. ipad: null,
  90. itouch: 2647
  91. }, {
  92. period: '2010 Q2',
  93. iphone: 2778,
  94. ipad: 2294,
  95. itouch: 2441
  96. }, {
  97. period: '2010 Q3',
  98. iphone: 4912,
  99. ipad: 1969,
  100. itouch: 2501
  101. }, {
  102. period: '2010 Q4',
  103. iphone: 3767,
  104. ipad: 3597,
  105. itouch: 5689
  106. }, {
  107. period: '2011 Q1',
  108. iphone: 6810,
  109. ipad: 1914,
  110. itouch: 2293
  111. }, {
  112. period: '2011 Q2',
  113. iphone: 5670,
  114. ipad: 4293,
  115. itouch: 1881
  116. }, {
  117. period: '2011 Q3',
  118. iphone: 4820,
  119. ipad: 3795,
  120. itouch: 1588
  121. }, {
  122. period: '2011 Q4',
  123. iphone: 15073,
  124. ipad: 5967,
  125. itouch: 5175
  126. }, {
  127. period: '2012 Q1',
  128. iphone: 10687,
  129. ipad: 4460,
  130. itouch: 2028
  131. }, {
  132. period: '2012 Q2',
  133. iphone: 8432,
  134. ipad: 5713,
  135. itouch: 1791
  136. }],
  137. xkey: 'period',
  138. ykeys: ['iphone', 'ipad', 'itouch'],
  139. labels: ['iPhone', 'iPad', 'iPod Touch'],
  140. pointSize: 2,
  141. hideHover: 'auto',
  142. lineColors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(0, 150, 136)']
  143. });
  144. } else if (type === 'donut') {
  145. Morris.Donut({
  146. element: element,
  147. data: [{
  148. label: 'Jam',
  149. value: 25
  150. }, {
  151. label: 'Frosted',
  152. value: 40
  153. }, {
  154. label: 'Custard',
  155. value: 25
  156. }, {
  157. label: 'Sugar',
  158. value: 10
  159. }],
  160. colors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(255, 152, 0)', 'rgb(0, 150, 136)'],
  161. formatter: function (y) {
  162. return y + '%'
  163. }
  164. });
  165. }
  166. }