morris-demo.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /* Morris color bar */
  2. $(function() {
  3. "use strict";
  4. Morris.Bar({
  5. element: 'color-bar',
  6. data: [{
  7. x: '2011 Q1',
  8. y: 0
  9. }, {
  10. x: '2011 Q2',
  11. y: 1
  12. }, {
  13. x: '2011 Q3',
  14. y: 2
  15. }, {
  16. x: '2011 Q4',
  17. y: 3
  18. }, {
  19. x: '2012 Q1',
  20. y: 4
  21. }, {
  22. x: '2012 Q2',
  23. y: 5
  24. }, {
  25. x: '2012 Q3',
  26. y: 6
  27. }, {
  28. x: '2012 Q4',
  29. y: 7
  30. }, {
  31. x: '2013 Q1',
  32. y: 8
  33. }],
  34. xkey: 'x',
  35. ykeys: ['y'],
  36. labels: ['Y'],
  37. barColors: function(row, series, type) {
  38. if (type === 'bar') {
  39. var red = Math.ceil(255 * row.y / this.ymax);
  40. return 'rgb(' + red + ',155,22)';
  41. } else {
  42. return '#000';
  43. }
  44. }
  45. });
  46. });
  47. /* Morris labels bar */
  48. $(function() {
  49. "use strict";
  50. var day_data = [{
  51. "period": "2012-10-01",
  52. "licensed": 3407,
  53. "sorned": 660
  54. }, {
  55. "period": "2012-09-30",
  56. "licensed": 3351,
  57. "sorned": 629
  58. }, {
  59. "period": "2012-09-29",
  60. "licensed": 3269,
  61. "sorned": 618
  62. }, {
  63. "period": "2012-09-20",
  64. "licensed": 3246,
  65. "sorned": 661
  66. }, {
  67. "period": "2012-09-19",
  68. "licensed": 3257,
  69. "sorned": 667
  70. }, {
  71. "period": "2012-09-18",
  72. "licensed": 3248,
  73. "sorned": 627
  74. }, {
  75. "period": "2012-09-17",
  76. "licensed": 3171,
  77. "sorned": 660
  78. }, {
  79. "period": "2012-09-16",
  80. "licensed": 3171,
  81. "sorned": 676
  82. }, {
  83. "period": "2012-09-15",
  84. "licensed": 3201,
  85. "sorned": 656
  86. }, {
  87. "period": "2012-09-10",
  88. "licensed": 3215,
  89. "sorned": 622
  90. }];
  91. Morris.Bar({
  92. element: 'labels-bar',
  93. data: day_data,
  94. xkey: 'period',
  95. ykeys: ['licensed', 'sorned'],
  96. labels: ['Licensed', 'SORN'],
  97. xLabelAngle: 60
  98. });
  99. });
  100. /* Morris stacked bars */
  101. $(function() {
  102. "use strict";
  103. Morris.Bar({
  104. element: 'stacked-bars',
  105. data: [{
  106. x: '2011 Q1',
  107. y: 3,
  108. z: 2,
  109. a: 3
  110. }, {
  111. x: '2011 Q2',
  112. y: 2,
  113. z: null,
  114. a: 1
  115. }, {
  116. x: '2011 Q3',
  117. y: 0,
  118. z: 2,
  119. a: 4
  120. }, {
  121. x: '2011 Q4',
  122. y: 2,
  123. z: 4,
  124. a: 3
  125. }],
  126. xkey: 'x',
  127. ykeys: ['y', 'z', 'a'],
  128. labels: ['Y', 'Z', 'A'],
  129. stacked: true
  130. });
  131. });
  132. /* Morris donut */
  133. $(function() {
  134. "use strict";
  135. Morris.Donut({
  136. element: 'donut',
  137. backgroundColor: '#fff',
  138. labelColor: '#ccc',
  139. colors: [
  140. '#4fb2ff',
  141. '#929292',
  142. '#67C69D',
  143. '#ff9393'
  144. ],
  145. data: [{
  146. value: 70,
  147. label: 'foo',
  148. formatted: 'at least 70%'
  149. }, {
  150. value: 15,
  151. label: 'bar',
  152. formatted: 'approx. 15%'
  153. }, {
  154. value: 10,
  155. label: 'baz',
  156. formatted: 'approx. 10%'
  157. }, {
  158. value: 5,
  159. label: 'A really really long label',
  160. formatted: 'at most 5%'
  161. }],
  162. formatter: function(x, data) {
  163. return data.formatted;
  164. }
  165. });
  166. });
  167. /* Morris decimal data */
  168. $(function() {
  169. "use strict";
  170. var decimal_data = [];
  171. for (var x = 0; x <= 360; x += 10) {
  172. decimal_data.push({
  173. x: x,
  174. y: 1.5 + 1.5 * Math.sin(Math.PI * x / 180).toFixed(4)
  175. });
  176. }
  177. window.m = Morris.Line({
  178. element: 'decimal-data',
  179. data: decimal_data,
  180. xkey: 'x',
  181. ykeys: ['y'],
  182. labels: ['sin(x)'],
  183. parseTime: false,
  184. hoverCallback: function(index, options, default_content) {
  185. var row = options.data[index];
  186. return default_content.replace("sin(x)", "1.5 + 1.5 sin(" + row.x + ")");
  187. },
  188. xLabelMargin: 10,
  189. integerYLabels: true
  190. });
  191. });
  192. /* Morris daytime */
  193. $(function() {
  194. "use strict";
  195. Morris.Area({
  196. element: 'daytime-bars',
  197. data: [{
  198. x: '2013-03-30 22:00:00',
  199. y: 3,
  200. z: 3
  201. }, {
  202. x: '2013-03-31 00:00:00',
  203. y: 2,
  204. z: 0
  205. }, {
  206. x: '2013-03-31 02:00:00',
  207. y: 0,
  208. z: 2
  209. }, {
  210. x: '2013-03-31 04:00:00',
  211. y: 4,
  212. z: 4
  213. }],
  214. xkey: 'x',
  215. ykeys: ['y', 'z'],
  216. labels: ['Y', 'Z']
  217. });
  218. });
  219. /* Author:
  220. */
  221. $(function() {
  222. // data stolen from http://howmanyleft.co.uk/vehicle/jaguar_'e'_type
  223. var tax_data = [{
  224. "period": "2011 Q3",
  225. "licensed": 3407,
  226. "sorned": 660
  227. }, {
  228. "period": "2011 Q2",
  229. "licensed": 3351,
  230. "sorned": 629
  231. }, {
  232. "period": "2011 Q1",
  233. "licensed": 3269,
  234. "sorned": 618
  235. }, {
  236. "period": "2010 Q4",
  237. "licensed": 3246,
  238. "sorned": 661
  239. }, {
  240. "period": "2009 Q4",
  241. "licensed": 3171,
  242. "sorned": 676
  243. }, {
  244. "period": "2008 Q4",
  245. "licensed": 3155,
  246. "sorned": 681
  247. }, {
  248. "period": "2007 Q4",
  249. "licensed": 3226,
  250. "sorned": 620
  251. }, {
  252. "period": "2006 Q4",
  253. "licensed": 3245,
  254. "sorned": null
  255. }, {
  256. "period": "2005 Q4",
  257. "licensed": 3289,
  258. "sorned": null
  259. }];
  260. Morris.Line({
  261. element: 'hero-graph',
  262. data: tax_data,
  263. xkey: 'period',
  264. ykeys: ['licensed', 'sorned'],
  265. labels: ['Licensed', 'Off the road']
  266. });
  267. Morris.Donut({
  268. element: 'hero-donut',
  269. data: [{
  270. label: 'Jam',
  271. value: 25
  272. }, {
  273. label: 'Frosted',
  274. value: 40
  275. }, {
  276. label: 'Custard',
  277. value: 25
  278. }, {
  279. label: 'Sugar',
  280. value: 10
  281. }],
  282. formatter: function(y) {
  283. return y + "%"
  284. }
  285. });
  286. Morris.Area({
  287. element: 'hero-area',
  288. data: [{
  289. period: '2010 Q1',
  290. iphone: 2666,
  291. ipad: null,
  292. itouch: 2647
  293. }, {
  294. period: '2010 Q2',
  295. iphone: 2778,
  296. ipad: 2294,
  297. itouch: 2441
  298. }, {
  299. period: '2010 Q3',
  300. iphone: 4912,
  301. ipad: 1969,
  302. itouch: 2501
  303. }, {
  304. period: '2010 Q4',
  305. iphone: 3767,
  306. ipad: 3597,
  307. itouch: 5689
  308. }, {
  309. period: '2011 Q1',
  310. iphone: 6810,
  311. ipad: 1914,
  312. itouch: 2293
  313. }, {
  314. period: '2011 Q2',
  315. iphone: 5670,
  316. ipad: 4293,
  317. itouch: 1881
  318. }, {
  319. period: '2011 Q3',
  320. iphone: 4820,
  321. ipad: 3795,
  322. itouch: 1588
  323. }, {
  324. period: '2011 Q4',
  325. iphone: 15073,
  326. ipad: 5967,
  327. itouch: 5175
  328. }, {
  329. period: '2012 Q1',
  330. iphone: 10687,
  331. ipad: 4460,
  332. itouch: 2028
  333. }, {
  334. period: '2012 Q2',
  335. iphone: 8432,
  336. ipad: 5713,
  337. itouch: 1791
  338. }],
  339. xkey: 'period',
  340. ykeys: ['iphone', 'ipad', 'itouch'],
  341. labels: ['iPhone', 'iPad', 'iPod Touch'],
  342. pointSize: 2,
  343. hideHover: 'auto'
  344. });
  345. Morris.Bar({
  346. element: 'hero-bar',
  347. data: [{
  348. device: 'iPhone',
  349. geekbench: 136
  350. }, {
  351. device: 'iPhone 3G',
  352. geekbench: 137
  353. }, {
  354. device: 'iPhone 3GS',
  355. geekbench: 275
  356. }, {
  357. device: 'iPhone 4',
  358. geekbench: 380
  359. }, {
  360. device: 'iPhone 4S',
  361. geekbench: 655
  362. }, {
  363. device: 'iPhone 5',
  364. geekbench: 1571
  365. }],
  366. xkey: 'device',
  367. ykeys: ['geekbench'],
  368. labels: ['Geekbench'],
  369. barRatio: 0.4,
  370. xLabelAngle: 35,
  371. hideHover: 'auto'
  372. });
  373. });