LineChart BarChart PieChart _统计图jsp代码">
当前位置:   article > 正文

2017-12-25 【jsp】显示各个类型的统计图表_统计图jsp代码

统计图jsp代码

项目用的是MINIUI

所以选择了ECharts来实现显示统计图表


1.下载并导入echarts.min.js【echarts官网


2.jsp代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>PieChart</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  6. <script src="${pageContext.request.contextPath}/template/ace/boot.js?version=<%=Consts.VERSION %>" type="text/javascript"></script>
  7. <script src="${pageContext.request.contextPath}/template/ace/echarts.min.js" type="text/javascript"></script>
  8. </head>
  9. <body>
  10. <input type="button" value="OpenChart" οnclick="buildChart()" />
  11. <h1>LineChart</h1>
  12. <div id="lineChart" style="height:500px;width:500px;"></div>
  13. <h1>BarChart</h1>
  14. <div id="barChart" style="height:500px;width:500px;"></div>
  15. <h1>PieChart</h1>
  16. <div id="pieChart" style="height:500px;width:500px;"></div>
  17. <script type="text/javascript">
  18. mini.parse();
  19. function buildChart() {
  20. var lineChartOption = {
  21. tooltip: {
  22. trigger: 'axis',
  23. axisPointer: {
  24. type: 'cross',
  25. label: {
  26. backgroundColor: '#6a7985'
  27. }
  28. }
  29. },
  30. legend: {
  31. data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
  32. },
  33. toolbox: {
  34. feature: {
  35. saveAsImage: {}
  36. }
  37. },
  38. grid: {
  39. left: '3%',
  40. right: '4%',
  41. bottom: '3%',
  42. containLabel: true
  43. },
  44. xAxis: [
  45. {
  46. type: 'category',
  47. boundaryGap: false,
  48. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  49. }
  50. ],
  51. yAxis: [
  52. {
  53. type: 'value'
  54. }
  55. ],
  56. series: [
  57. {
  58. name: '邮件营销',
  59. type: 'line',
  60. stack: '总量',
  61. areaStyle: { normal: {} },
  62. data: [120, 132, 101, 134, 90, 230, 210]
  63. },
  64. {
  65. name: '联盟广告',
  66. type: 'line',
  67. stack: '总量',
  68. areaStyle: { normal: {} },
  69. data: [220, 182, 191, 234, 290, 330, 310]
  70. },
  71. {
  72. name: '视频广告',
  73. type: 'line',
  74. stack: '总量',
  75. areaStyle: { normal: {} },
  76. data: [150, 232, 201, 154, 190, 330, 410]
  77. },
  78. {
  79. name: '直接访问',
  80. type: 'line',
  81. stack: '总量',
  82. areaStyle: { normal: {} },
  83. data: [320, 332, 301, 334, 390, 330, 320]
  84. },
  85. {
  86. name: '搜索引擎',
  87. type: 'line',
  88. stack: '总量',
  89. label: {
  90. normal: {
  91. show: true,
  92. position: 'top'
  93. }
  94. },
  95. areaStyle: { normal: {} },
  96. data: [820, 932, 901, 934, 1290, 1330, 1320]
  97. }
  98. ]
  99. };
  100. var barChartOption = {
  101. title: {
  102. text: option.title.text,
  103. subtext: '纯属虚构',
  104. x: 'center'
  105. },
  106. color: ['#3398DB'],
  107. tooltip: {
  108. trigger: 'axis',
  109. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  110. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  111. }
  112. },
  113. grid: {
  114. left: '3%',
  115. right: '4%',
  116. bottom: '3%',
  117. containLabel: true
  118. },
  119. xAxis: [
  120. {
  121. type: 'category',
  122. data: option.xAxis[0].data,
  123. }
  124. ],
  125. yAxis: [
  126. {
  127. type: 'value'
  128. }
  129. ],
  130. series: [
  131. {
  132. name: '直接访问',
  133. type: 'bar',
  134. barWidth: '60%',
  135. data: [10, 52, 200, 334, 390, 330, 220]
  136. }
  137. ]
  138. };
  139. var pieChartOption = {
  140. title: {
  141. text: '某站点用户访问来源',
  142. subtext: '纯属虚构',
  143. x: 'center'
  144. },
  145. tooltip: {
  146. trigger: 'item',
  147. formatter: "{a} <br/>{b} : {c} ({d}%)"
  148. },
  149. legend: {
  150. orient: 'vertical',
  151. left: 'left',
  152. data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
  153. },
  154. series: [
  155. {
  156. name: '访问来源',
  157. type: 'pie',
  158. radius: '55%',
  159. center: ['50%', '60%'],
  160. data: [
  161. { value: 335, name: '直接访问' },
  162. { value: 310, name: '邮件营销' },
  163. { value: 234, name: '联盟广告' },
  164. { value: 135, name: '视频广告' },
  165. { value: 1548, name: '搜索引擎' }
  166. ],
  167. itemStyle: {
  168. emphasis: {
  169. shadowBlur: 10,
  170. shadowOffsetX: 0,
  171. shadowColor: 'rgba(0, 0, 0, 0.5)'
  172. }
  173. }
  174. }
  175. ]
  176. };
  177. var chart = echarts.init(document.getElementById('lineChart'));
  178. chart.setOption(lineChartOption);
  179. var chart = echarts.init(document.getElementById('barChart'));
  180. chart.setOption(barChartOption);
  181. var chart = echarts.init(document.getElementById('pieChart'));
  182. chart.setOption(pieChartOption);
  183. }
  184. </script>
  185. </body>
  186. </html>



本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/171110
推荐阅读
相关标签
  

闽ICP备14008679号