l.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>m</title>
  6. <link rel="stylesheet" href="assets/libs/layui/css/layui.css"/>
  7. </head>
  8. <body style="margin: 20px;">
  9. <form class="layui-form" action="">
  10. <div class="layui-form-item">
  11. <label class="layui-form-label"></label>
  12. <div class="layui-input-block">
  13. <label class="layui-form-label">公共属性</label>
  14. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="title" lay-text="左边|中间">
  15. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="toolbox" lay-text="打开工具栏|关闭工具栏">
  16. </div>
  17. </div>
  18. <div class="layui-form-item">
  19. <label class="layui-form-label"></label>
  20. <div class="layui-input-block">
  21. <input type="radio" name="ecType" value="1" lay-filter="ecType" title="折线图" checked>
  22. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="rotate" lay-text="文字倾斜|默认">
  23. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="normal" lay-text="显示数据|默认">
  24. </div>
  25. </div>
  26. <div class="layui-form-item">
  27. <label class="layui-form-label"></label>
  28. <div class="layui-input-block">
  29. <input type="radio" name="ecType" value="2" lay-filter="ecType" title="饼图">
  30. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="legend" lay-text="数据种类|默认">
  31. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="normal" lay-text="显示数据|默认">
  32. </div>
  33. </div>
  34. </form>
  35. <div id="mainView" style="height:500px; margin: 0"></div>
  36. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  37. <legend>今日访问企业列表</legend>
  38. </fieldset>
  39. <div class="layui-collapse" lay-accordion id="mainLineInfo" lay-filter="test">
  40. </div>
  41. </body>
  42. <!-- js部分 -->
  43. <script src="assets/libs/jquery/jquery-3.2.1.min.js"></script>
  44. <script src="assets/libs/layui/layui.js"></script>
  45. <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
  46. <script src="assets/libs/echarts/theme/vintage.js"></script>
  47. <script src="assets/libs/echarts/theme/shine.js"></script>
  48. <script src="assets/libs/echarts/theme/macarons.js"></script>
  49. <script src="assets/libs/echarts/theme/roma.js"></script>
  50. <script src="assets/libs/echarts/plus/echarts-util.js"></script>
  51. <!--<script src="assets/libs/echarts/plus/mysetTheme.js"></script>-->
  52. <script>
  53. layui.use(['form', 'element', 'util', 'layer'], function () {
  54. var element = layui.element;
  55. var layer = layui.layer;
  56. var form = layui.form;
  57. var openStyle = {ecType: "1", toolbox: true, rotate: true, normal: true, legend: true, title: true};
  58. //监听指定开关
  59. form.on('radio(ecType)', function (data) {
  60. var level = data.value;
  61. openStyle.ecType = level;
  62. loadMainView(openStyle);
  63. });
  64. form.on('switch(toolbox)', function () {
  65. openStyle.toolbox = this.checked;
  66. loadMainView(openStyle);
  67. });
  68. form.on('switch(rotate)', function () {
  69. openStyle.rotate = this.checked;
  70. loadMainView(openStyle);
  71. });
  72. form.on('switch(legend)', function () {
  73. openStyle.legend = this.checked;
  74. loadMainView(openStyle);
  75. });
  76. form.on('switch(normal)', function () {
  77. openStyle.normal = this.checked;
  78. loadMainView(openStyle);
  79. });
  80. form.on('switch(title)', function () {
  81. openStyle.title = this.checked;
  82. loadMainView(openStyle);
  83. });
  84. $.ajax({
  85. type: "get",
  86. url: "http://127.0.0.1:8899/3rd/outData/ccInfo",
  87. data: {},
  88. success: function (res) {
  89. var ul = "";
  90. $.each(res.data, function (index, value) {
  91. ul += `<div class="layui-colla-item">
  92. <h2 class="layui-colla-title" id="${value.cId}">${value.cName}</h2>
  93. <div class="layui-colla-content ${index == 0 ? 'layui-show' : ''}" id="${value.cId}_">
  94. <!-- <p>${value.cName}</p>-->
  95. </div>
  96. </div>`;
  97. });
  98. $("#mainLineInfo").html(ul);
  99. element.init();
  100. }
  101. });
  102. //监听折叠
  103. element.on('collapse(test)', function (data) {
  104. if (data.show) {
  105. var id = data.title[0].id;
  106. $.ajax({
  107. type: "get",
  108. url: "http://127.0.0.1:8899/3rd/outData/ccInfoA",
  109. data: {cId: id},
  110. success: function (res) {
  111. var ul = "";
  112. $.each(res.data, function (index, value) {
  113. ul += `<span class="layui-badge layui-bg-blue">${value.val}</span>&nbsp;&nbsp;`;
  114. });
  115. $("#" + id + "_").html(ul);
  116. element.init();
  117. }
  118. });
  119. }
  120. });
  121. loadMainView(openStyle);
  122. function loadMainView(openStyle) {
  123. console.log(openStyle)
  124. $.ajax({
  125. type: "get",
  126. url: "http://127.0.0.1:8899/3rd/outData/cc",
  127. data: {},
  128. success: function (res) {
  129. var initChart = null;
  130. var option = null;
  131. if (openStyle.ecType === "1") {
  132. option = MyEcharts.EchartsOption.Line("折线图", "单位(家)", res.data);
  133. } else if (openStyle.ecType === "2") {
  134. option = MyEcharts.EchartsOption.pie("环形饼图", "种类数(份)", res.data, ['40%', '60%']);
  135. }
  136. option.tooltip = {trigger: 'axis'}
  137. //标题显示
  138. if (openStyle.title) {
  139. option.title = {text: '环形饼图', subtext: '纯属虚构', left: 'center'}
  140. }
  141. //工具栏
  142. if (openStyle.toolbox) {
  143. option.toolbox = {show: true,
  144. feature: {
  145. dataZoom: {yAxisIndex: 'none'},
  146. dataView: {readOnly: false},
  147. magicType: {type: ['line', 'bar']},
  148. restore: {},
  149. saveAsImage: {}
  150. }
  151. }
  152. }
  153. //文字倾斜
  154. if (openStyle.ecType === "1" && openStyle.rotate) {
  155. option.xAxis[0].axisLabel = {interval: 0, rotate: 50};
  156. }
  157. if (openStyle.ecType === "2" && openStyle.legend) {
  158. //pie 显示在左边
  159. option.legend = {orient: 'vertical', left: 'left',};
  160. }
  161. //显示折线数据
  162. if (openStyle.normal) {
  163. option.series[0].label = {normal: {show: true}};
  164. }
  165. console.log(option);
  166. initChart = MyEcharts.initChart(option, "mainView");
  167. setTimeout(function () {
  168. window.onresize = function () {
  169. initChartLine.resize();
  170. }
  171. }, 200);
  172. //
  173. // option.tooltip = {trigger: 'axis'}
  174. // option.toolbox = {show: true, feature: {dataZoom: {yAxisIndex: 'none'}, dataView: {readOnly: false}, magicType: {type: ['line', 'bar']}, restore: {}, saveAsImage: {}}}
  175. // option.legend = {orient: 'vertical', left: 'left',};
  176. // option.series[0].itemStyle = {borderRadius: 10, borderColor: '#fff', borderWidth: 2};
  177. // // option.series[0].emphasis = {label: {show: true, fontSize: '40', fontWeight: 'bold'}};
  178. // // option.series[0].label = {show: false, position: 'center'};
  179. // // option.series[0].labelLine = {show: false};
  180. // if (openStyle.ecType === "2") {
  181. // initChart = MyEcharts.initChart(option, "mainView");
  182. // }
  183. // setTimeout(function () {
  184. // window.onresize = function () {
  185. // initChart.resize();
  186. // }
  187. // }, 200);
  188. }
  189. });
  190. }
  191. });
  192. //区域填充样式(渐变)
  193. /*option.series[0].areaStyle = {
  194. color: {
  195. type: 'linear', // 线性渐变:linear,径向渐变:radial
  196. x: 0,
  197. y: 0,
  198. x2: 0,
  199. y2: 1,
  200. colorStops: [{
  201. offset: 0.2, color: '#838CFF' // 0% 处的颜色
  202. }, {
  203. offset: 0.6, color: 'transparent' // 100% 处的颜色
  204. }],
  205. global: false // 缺省为 false
  206. }
  207. // 纹理填充
  208. // color: {
  209. // image: imageDom, // 支持为 HTMLImageElement, HTMLCanvasElement,不支持路径字符串
  210. // repeat: 'repeat' // 是否平铺,可以是 'repeat-x', 'repeat-y', 'no-repeat'
  211. // }
  212. }*/
  213. // var initChartLine = MyEcharts.initChart(option, "mainLine");
  214. </script>
  215. </html>