morris.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*---- morrisBar2----*/
  2. $(function(e) {
  3. 'use strict';
  4. new Morris.Area({
  5. element: 'morrisBar2',
  6. data: [{
  7. x: '2010 Q4',
  8. y: 3,
  9. z: 7
  10. }, {
  11. x: '2011 Q1',
  12. y: 3,
  13. z: 4
  14. }, {
  15. x: '2011 Q2',
  16. y: null,
  17. z: 1
  18. }, {
  19. x: '2011 Q3',
  20. y: 2,
  21. z: 5
  22. }, {
  23. x: '2011 Q4',
  24. y: 8,
  25. z: 2
  26. }, {
  27. x: '2012 Q1',
  28. y: 4,
  29. z: 4
  30. }],
  31. xkey: 'x',
  32. ykeys: ['y', 'z'],
  33. lineColors: ['#6c5ffc', '#05c3fb'],
  34. labels: ['Y', 'Z'],
  35. resize: true
  36. }).on('click', function(i, row) {
  37. console.log(i, row);
  38. });
  39. /*---- morrisBar3----*/
  40. new Morris.Area({
  41. element: 'morrisBar3',
  42. behaveLikeLine: true,
  43. data: [{
  44. x: '2011 Q1',
  45. y: 3,
  46. z: 3
  47. }, {
  48. x: '2011 Q2',
  49. y: 2,
  50. z: 1
  51. }, {
  52. x: '2011 Q3',
  53. y: 2,
  54. z: 4
  55. }, {
  56. x: '2011 Q4',
  57. y: 3,
  58. z: 3
  59. }],
  60. xkey: 'x',
  61. ykeys: ['y', 'z'],
  62. lineColors: ['#6c5ffc', '#05c3fb'],
  63. labels: ['Y', 'Z'],
  64. resize: true
  65. });
  66. /*---- morrisBar4----*/
  67. new Morris.Bar({
  68. element: 'morrisBar4',
  69. data: [{
  70. x: '2011 Q1',
  71. y: 0
  72. }, {
  73. x: '2011 Q2',
  74. y: 1
  75. }, {
  76. x: '2011 Q3',
  77. y: 2
  78. }, {
  79. x: '2011 Q4',
  80. y: 3
  81. }, {
  82. x: '2012 Q1',
  83. y: 4
  84. }, {
  85. x: '2012 Q2',
  86. y: 5
  87. }, {
  88. x: '2012 Q3',
  89. y: 6
  90. }, {
  91. x: '2012 Q4',
  92. y: 7
  93. }, {
  94. x: '2013 Q1',
  95. y: 8
  96. }],
  97. xkey: 'x',
  98. ykeys: ['y'],
  99. labels: ['Y'],
  100. barColors: function(row, series, type) {
  101. if (type === 'bar') {
  102. var red = Math.ceil(0 * row.y / this.ymax);
  103. return '#6c5ffc';
  104. } else {
  105. return '#000';
  106. }
  107. }
  108. });
  109. var day_data = [{
  110. "period": "Jan",
  111. "licensed": 3407,
  112. "sorned": 660
  113. }, {
  114. "period": "Feb",
  115. "licensed": 3351,
  116. "sorned": 629
  117. }, {
  118. "period": "Mar",
  119. "licensed": 3269,
  120. "sorned": 618
  121. }, {
  122. "period": "Apr",
  123. "licensed": 3246,
  124. "sorned": 661
  125. }, {
  126. "period": "May",
  127. "licensed": 3257,
  128. "sorned": 667
  129. }, {
  130. "period": "June",
  131. "licensed": 3248,
  132. "sorned": 627
  133. }, {
  134. "period": "July",
  135. "licensed": 3171,
  136. "sorned": 660
  137. }, {
  138. "period": "Aug",
  139. "licensed": 3171,
  140. "sorned": 676
  141. }, {
  142. "period": "Sept",
  143. "licensed": 3201,
  144. "sorned": 656
  145. }, {
  146. "period": "Oct",
  147. "licensed": 3215,
  148. "sorned": 622
  149. }];
  150. /*---- morrisBar5----*/
  151. new Morris.Bar({
  152. element: 'morrisBar5',
  153. data: day_data,
  154. xkey: 'period',
  155. ykeys: ['licensed', 'sorned'],
  156. labels: ['Licensed', 'SORN'],
  157. barColors: ['#6c5ffc', '#05c3fb'],
  158. xLabelAngle: 0,
  159. resize: true
  160. });
  161. var nReloads = 0;
  162. function data(offset) {
  163. var ret = [];
  164. for (var x = 0; x <= 360; x += 10) {
  165. var v = (offset + x) % 360;
  166. ret.push({
  167. x: x,
  168. y: Math.sin(Math.PI * v / 180).toFixed(4),
  169. z: Math.cos(Math.PI * v / 180).toFixed(4)
  170. });
  171. }
  172. return ret;
  173. }
  174. /*---- morrisBar6----*/
  175. var graph = Morris.Line({
  176. element: 'morrisBar6',
  177. data: data(0),
  178. xkey: 'x',
  179. ykeys: ['y', 'z'],
  180. labels: ['data1', 'data2'],
  181. lineColors: ['#6c5ffc', '#05c3fb'],
  182. parseTime: false,
  183. ymin: -1.0,
  184. ymax: 1.0,
  185. hideHover: true,
  186. resize: true
  187. });
  188. function update() {
  189. nReloads++;
  190. graph.setData(data(5 * nReloads));
  191. $('#reloadStatus').text(nReloads + ' reloads');
  192. }
  193. // setInterval(update, 100);
  194. /*---- morrisBar7----*/
  195. var day_data = [{
  196. "period": "2012-10-01",
  197. "licensed": 3407,
  198. "sorned": 660
  199. }, {
  200. "period": "2012-09-30",
  201. "licensed": 3351,
  202. "sorned": 629
  203. }, {
  204. "period": "2012-09-29",
  205. "licensed": 3269,
  206. "sorned": 618
  207. }, {
  208. "period": "2012-09-20",
  209. "licensed": 3246,
  210. "sorned": 661
  211. }, {
  212. "period": "2012-09-19",
  213. "licensed": 3257,
  214. "sorned": 667
  215. }, {
  216. "period": "2012-09-18",
  217. "licensed": 3248,
  218. "sorned": 627
  219. }, {
  220. "period": "2012-09-17",
  221. "licensed": 3171,
  222. "sorned": 660
  223. }, {
  224. "period": "2012-09-16",
  225. "licensed": 3171,
  226. "sorned": 676
  227. }, {
  228. "period": "2012-09-15",
  229. "licensed": 3201,
  230. "sorned": 656
  231. }, {
  232. "period": "2012-09-10",
  233. "licensed": 3215,
  234. "sorned": 622
  235. }];
  236. new Morris.Line({
  237. element: 'morrisBar7',
  238. data: day_data,
  239. xkey: 'period',
  240. ykeys: ['licensed', 'sorned'],
  241. labels: ['Licensed', 'SORN'],
  242. lineColors: ['#6c5ffc', '#05c3fb'],
  243. resize: true,
  244. });
  245. /*---- morrisBar8----*/
  246. new Morris.Donut({
  247. element: 'morrisBar8',
  248. data: [{
  249. value: 50,
  250. label: 'data1'
  251. }, {
  252. value: 35,
  253. label: 'data2'
  254. }, {
  255. value: 10,
  256. label: 'data3'
  257. }],
  258. backgroundColor: 'rgba(119, 119, 142, 0.2)',
  259. labelColor: '#77778e',
  260. colors: ['#6c5ffc', '#05c3fb', '#09ad95'],
  261. resize: true,
  262. formatter: function(x) {
  263. return x + "%"
  264. }
  265. }).on('click', function(i, row) {
  266. console.log(i, row);
  267. });
  268. /*---- morrisBar9----*/
  269. new Morris.Donut({
  270. element: 'morrisBar9',
  271. data: [{
  272. value: 35,
  273. label: 'data1'
  274. }, {
  275. value: 25,
  276. label: 'data2'
  277. }, {
  278. value: 15,
  279. label: 'data3'
  280. }, {
  281. value: 15,
  282. label: 'data4'
  283. }, {
  284. value: 10,
  285. label: 'data5'
  286. }, {
  287. value: 10,
  288. label: 'data6'
  289. }],
  290. backgroundColor: 'rgba(119, 119, 142, 0.2)',
  291. labelColor: '#77778e',
  292. resize: true,
  293. colors: ['#6c5ffc', '#05c3fb', '#09ad95', '#1170e4', '#f82649', '#f7b731'],
  294. formatter: function(x) {
  295. return x + "%"
  296. }
  297. });
  298. });