examples.charts.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. (function( $ ) {
  2. 'use strict';
  3. /*
  4. Flot: Basic
  5. */
  6. (function() {
  7. var plot = $.plot('#flotBasic', flotBasicData, {
  8. series: {
  9. lines: {
  10. show: true,
  11. fill: true,
  12. lineWidth: 1,
  13. fillColor: {
  14. colors: [{
  15. opacity: 0.45
  16. }, {
  17. opacity: 0.45
  18. }]
  19. }
  20. },
  21. points: {
  22. show: true
  23. },
  24. shadowSize: 0
  25. },
  26. grid: {
  27. hoverable: true,
  28. clickable: true,
  29. borderColor: 'rgba(0,0,0,0.1)',
  30. borderWidth: 1,
  31. labelMargin: 15,
  32. backgroundColor: 'transparent'
  33. },
  34. yaxis: {
  35. min: 0,
  36. max: 200,
  37. color: 'rgba(0,0,0,0.1)'
  38. },
  39. xaxis: {
  40. color: 'rgba(0,0,0,0.1)'
  41. },
  42. tooltip: true,
  43. tooltipOpts: {
  44. content: '%s: Value of %x is %y',
  45. shifts: {
  46. x: -60,
  47. y: 25
  48. },
  49. defaultTheme: false
  50. }
  51. });
  52. })();
  53. /*
  54. Flot: Real-Time
  55. */
  56. (function() {
  57. var data = [],
  58. totalPoints = 300;
  59. function getRandomData() {
  60. if (data.length > 0)
  61. data = data.slice(1);
  62. // Do a random walk
  63. while (data.length < totalPoints) {
  64. var prev = data.length > 0 ? data[data.length - 1] : 50,
  65. y = prev + Math.random() * 10 - 5;
  66. if (y < 0) {
  67. y = 0;
  68. } else if (y > 100) {
  69. y = 100;
  70. }
  71. data.push(y);
  72. }
  73. // Zip the generated y values with the x values
  74. var res = [];
  75. for (var i = 0; i < data.length; ++i) {
  76. res.push([i, data[i]])
  77. }
  78. return res;
  79. }
  80. var plot = $.plot('#flotRealTime', [getRandomData()], {
  81. colors: ['#8CC9E8'],
  82. series: {
  83. lines: {
  84. show: true,
  85. fill: true,
  86. lineWidth: 1,
  87. fillColor: {
  88. colors: [{
  89. opacity: 0.45
  90. }, {
  91. opacity: 0.45
  92. }]
  93. }
  94. },
  95. points: {
  96. show: false
  97. },
  98. shadowSize: 0
  99. },
  100. grid: {
  101. borderColor: 'rgba(0,0,0,0.1)',
  102. borderWidth: 1,
  103. labelMargin: 15,
  104. backgroundColor: 'transparent'
  105. },
  106. yaxis: {
  107. min: 0,
  108. max: 100,
  109. color: 'rgba(0,0,0,0.1)'
  110. },
  111. xaxis: {
  112. show: false
  113. }
  114. });
  115. function update() {
  116. plot.setData([getRandomData()]);
  117. // Since the axes don't change, we don't need to call plot.setupGrid()
  118. plot.draw();
  119. setTimeout(update, $( 'html' ).hasClass( 'mobile-device' ) ? 1000 : 30 );
  120. }
  121. update();
  122. })();
  123. /*
  124. Flot: Bars
  125. */
  126. (function() {
  127. var plot = $.plot('#flotBars', [flotBarsData], {
  128. colors: ['#8CC9E8'],
  129. series: {
  130. bars: {
  131. show: true,
  132. barWidth: 0.8,
  133. align: 'center'
  134. }
  135. },
  136. xaxis: {
  137. mode: 'categories',
  138. tickLength: 0
  139. },
  140. grid: {
  141. hoverable: true,
  142. clickable: true,
  143. borderColor: 'rgba(0,0,0,0.1)',
  144. borderWidth: 1,
  145. labelMargin: 15,
  146. backgroundColor: 'transparent'
  147. },
  148. tooltip: true,
  149. tooltipOpts: {
  150. content: '%y',
  151. shifts: {
  152. x: -10,
  153. y: 20
  154. },
  155. defaultTheme: false
  156. }
  157. });
  158. })();
  159. /*
  160. Flot: Pie
  161. */
  162. (function() {
  163. var plot = $.plot('#flotPie', flotPieData, {
  164. series: {
  165. pie: {
  166. show: true,
  167. combine: {
  168. color: '#999',
  169. threshold: 0.1
  170. }
  171. }
  172. },
  173. legend: {
  174. show: false
  175. },
  176. grid: {
  177. hoverable: true,
  178. clickable: true
  179. }
  180. });
  181. })();
  182. /*
  183. Morris: Line
  184. */
  185. Morris.Line({
  186. resize: true,
  187. element: 'morrisLine',
  188. data: morrisLineData,
  189. xkey: 'y',
  190. ykeys: ['a', 'b'],
  191. labels: ['Series A', 'Series B'],
  192. hideHover: true,
  193. lineColors: ['#0088cc', '#734ba9'],
  194. });
  195. /*
  196. Morris: Donut
  197. */
  198. Morris.Donut({
  199. resize: true,
  200. element: 'morrisDonut',
  201. data: morrisDonutData,
  202. colors: ['#0088cc', '#734ba9', '#E36159']
  203. });
  204. /*
  205. Morris: Bar
  206. */
  207. Morris.Bar({
  208. resize: true,
  209. element: 'morrisBar',
  210. data: morrisBarData,
  211. xkey: 'y',
  212. ykeys: ['a', 'b'],
  213. labels: ['Series A', 'Series B'],
  214. hideHover: true,
  215. barColors: ['#0088cc', '#2baab1']
  216. });
  217. /*
  218. Morris: Area
  219. */
  220. Morris.Area({
  221. resize: true,
  222. element: 'morrisArea',
  223. data: morrisAreaData,
  224. xkey: 'y',
  225. ykeys: ['a', 'b'],
  226. labels: ['Series A', 'Series B'],
  227. lineColors: ['#0088cc', '#2baab1'],
  228. fillOpacity: 0.7,
  229. hideHover: true
  230. });
  231. /*
  232. Morris: Stacked
  233. */
  234. Morris.Bar({
  235. resize: true,
  236. element: 'morrisStacked',
  237. data: morrisStackedData,
  238. xkey: 'y',
  239. ykeys: ['a', 'b'],
  240. labels: ['Series A', 'Series B'],
  241. barColors: ['#0088cc', '#2baab1'],
  242. fillOpacity: 0.7,
  243. smooth: false,
  244. stacked: true,
  245. hideHover: true
  246. });
  247. /*
  248. Gauge: Basic
  249. */
  250. (function() {
  251. var target = $('#gaugeBasic'),
  252. opts = $.extend(true, {}, {
  253. lines: 12, // The number of lines to draw
  254. angle: 0.12, // The length of each line
  255. lineWidth: 0.5, // The line thickness
  256. pointer: {
  257. length: 0.7, // The radius of the inner circle
  258. strokeWidth: 0.05, // The rotation offset
  259. color: '#444' // Fill color
  260. },
  261. limitMax: 'true', // If true, the pointer will not go past the end of the gauge
  262. colorStart: '#0088CC', // Colors
  263. colorStop: '#0088CC', // just experiment with them
  264. strokeColor: '#F1F1F1', // to see which ones work best for you
  265. generateGradient: true
  266. }, target.data('plugin-options'));
  267. var gauge = new Gauge(target.get(0)).setOptions(opts);
  268. gauge.maxValue = opts.maxValue; // set max gauge value
  269. gauge.animationSpeed = 32; // set animation speed (32 is default value)
  270. gauge.set(opts.value); // set actual value
  271. gauge.setTextField(document.getElementById("gaugeBasicTextfield"));
  272. })();
  273. /*
  274. Gauge: Alternative
  275. */
  276. (function() {
  277. var target = $('#gaugeAlternative'),
  278. opts = $.extend(true, {}, {
  279. lines: 12, // The number of lines to draw
  280. angle: 0.12, // The length of each line
  281. lineWidth: 0.5, // The line thickness
  282. pointer: {
  283. length: 0.7, // The radius of the inner circle
  284. strokeWidth: 0.05, // The rotation offset
  285. color: '#444' // Fill color
  286. },
  287. limitMax: 'true', // If true, the pointer will not go past the end of the gauge
  288. colorStart: '#2BAAB1', // Colors
  289. colorStop: '#2BAAB1', // just experiment with them
  290. strokeColor: '#F1F1F1', // to see which ones work best for you
  291. generateGradient: true
  292. }, target.data('plugin-options'));
  293. var gauge = new Gauge(target.get(0)).setOptions(opts);
  294. gauge.maxValue = opts.maxValue; // set max gauge value
  295. gauge.animationSpeed = 32; // set animation speed (32 is default value)
  296. gauge.set(opts.value); // set actual value
  297. gauge.setTextField(document.getElementById("gaugeAlternativeTextfield"));
  298. })();
  299. /*
  300. Liquid Meter
  301. */
  302. $('#meter').liquidMeter({
  303. shape: 'circle',
  304. color: '#0088CC',
  305. background: '#F9F9F9',
  306. fontSize: '24px',
  307. fontWeight: '600',
  308. stroke: '#F2F2F2',
  309. textColor: '#333',
  310. liquidOpacity: 0.9,
  311. liquidPalette: ['#333'],
  312. speed: 3000,
  313. animate: !$.browser.mobile
  314. });
  315. /*
  316. Liquid Meter Dark
  317. */
  318. $('#meterDark').liquidMeter({
  319. shape: 'circle',
  320. color: '#0088CC',
  321. background: '#272A31',
  322. stroke: '#33363F',
  323. fontSize: '24px',
  324. fontWeight: '600',
  325. textColor: '#FFFFFF',
  326. liquidOpacity: 0.9,
  327. liquidPalette: ['#0088CC'],
  328. speed: 3000,
  329. animate: !$.browser.mobile
  330. });
  331. /*
  332. Sparkline: Line
  333. */
  334. $("#sparklineLine").sparkline(sparklineLineData, {
  335. type: 'line',
  336. width: '80',
  337. height: '30',
  338. lineColor: '#0088cc'
  339. });
  340. /*
  341. Sparkline: Bar
  342. */
  343. $("#sparklineBar").sparkline(sparklineBarData, {
  344. type: 'bar',
  345. width: '80',
  346. height: '30',
  347. barColor: '#0088cc',
  348. negBarColor: '#B20000'
  349. });
  350. /*
  351. Sparkline: Tristate
  352. */
  353. $("#sparklineTristate").sparkline(sparklineTristateData, {
  354. type: 'tristate',
  355. width: '80',
  356. height: '30',
  357. posBarColor: '#0088cc',
  358. negBarColor: '#B20000'
  359. });
  360. /*
  361. Sparkline: Discrete
  362. */
  363. $("#sparklineDiscrete").sparkline(sparklineDiscreteData, {
  364. type: 'discrete',
  365. width: '80',
  366. height: '30',
  367. lineColor: '#0088cc'
  368. });
  369. /*
  370. Sparkline: Bullet
  371. */
  372. $("#sparklineBullet").sparkline(sparklineBulletData, {
  373. type: 'bullet',
  374. width: '80',
  375. height: '30',
  376. targetColor: '#ff7f00',
  377. performanceColor: '#0088cc'
  378. });
  379. /*
  380. Sparkline: Pie
  381. */
  382. $("#sparklinePie").sparkline(sparklinePieData, {
  383. type: 'pie',
  384. height: '30',
  385. barColor: '#0088cc'
  386. });
  387. }).apply( this, [ jQuery ]);