dashboard.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
  2. var Controller = {
  3. index: function () {
  4. // 基于准备好的dom,初始化echarts实例
  5. var myChart = Echarts.init(document.getElementById('echart'), 'walden');
  6. // 指定图表的配置项和数据
  7. var option = {
  8. title: {
  9. text: '',
  10. subtext: ''
  11. },
  12. tooltip: {
  13. trigger: 'axis'
  14. },
  15. legend: {
  16. data: [__('Sales'), __('Orders')]
  17. },
  18. toolbox: {
  19. show: false,
  20. feature: {
  21. magicType: {show: true, type: ['stack', 'tiled']},
  22. saveAsImage: {show: true}
  23. }
  24. },
  25. xAxis: {
  26. type: 'category',
  27. boundaryGap: false,
  28. data: Orderdata.column
  29. },
  30. yAxis: {},
  31. grid: [{
  32. left: 'left',
  33. top: 'top',
  34. right: '10',
  35. bottom: 30
  36. }],
  37. series: [{
  38. name: __('Sales'),
  39. type: 'line',
  40. smooth: true,
  41. areaStyle: {
  42. normal: {}
  43. },
  44. lineStyle: {
  45. normal: {
  46. width: 1.5
  47. }
  48. },
  49. data: Orderdata.paydata
  50. },
  51. {
  52. name: __('Orders'),
  53. type: 'line',
  54. smooth: true,
  55. areaStyle: {
  56. normal: {}
  57. },
  58. lineStyle: {
  59. normal: {
  60. width: 1.5
  61. }
  62. },
  63. data: Orderdata.createdata
  64. }]
  65. };
  66. // 使用刚指定的配置项和数据显示图表。
  67. myChart.setOption(option);
  68. //动态添加数据,可以通过Ajax获取数据然后填充
  69. setInterval(function () {
  70. Orderdata.column.push((new Date()).toLocaleTimeString().replace(/^\D*/, ''));
  71. var amount = Math.floor(Math.random() * 200) + 20;
  72. Orderdata.createdata.push(amount);
  73. Orderdata.paydata.push(Math.floor(Math.random() * amount) + 1);
  74. //按自己需求可以取消这个限制
  75. if (Orderdata.column.length >= 20) {
  76. //移除最开始的一条数据
  77. Orderdata.column.shift();
  78. Orderdata.paydata.shift();
  79. Orderdata.createdata.shift();
  80. }
  81. myChart.setOption({
  82. xAxis: {
  83. data: Orderdata.column
  84. },
  85. series: [{
  86. name: __('Sales'),
  87. data: Orderdata.paydata
  88. },
  89. {
  90. name: __('Orders'),
  91. data: Orderdata.createdata
  92. }]
  93. });
  94. }, 2000);
  95. $(window).resize(function () {
  96. myChart.resize();
  97. });
  98. $(document).on("click", ".btn-checkversion", function () {
  99. top.window.$("[data-toggle=checkupdate]").trigger("click");
  100. });
  101. $(document).on("click", ".btn-refresh", function () {
  102. setTimeout(function () {
  103. myChart.resize();
  104. }, 0);
  105. });
  106. }
  107. };
  108. return Controller;
  109. });