LineChart BarChart PieChart _统计图jsp代码">
赞
踩
项目用的是MINIUI
所以选择了ECharts来实现显示统计图表
1.下载并导入echarts.min.js【echarts官网】
2.jsp代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>PieChart</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <script src="${pageContext.request.contextPath}/template/ace/boot.js?version=<%=Consts.VERSION %>" type="text/javascript"></script>
- <script src="${pageContext.request.contextPath}/template/ace/echarts.min.js" type="text/javascript"></script>
- </head>
- <body>
- <input type="button" value="OpenChart" οnclick="buildChart()" />
- <h1>LineChart</h1>
- <div id="lineChart" style="height:500px;width:500px;"></div>
- <h1>BarChart</h1>
- <div id="barChart" style="height:500px;width:500px;"></div>
- <h1>PieChart</h1>
- <div id="pieChart" style="height:500px;width:500px;"></div>
- <script type="text/javascript">
- mini.parse();
- function buildChart() {
-
- var lineChartOption = {
-
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross',
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
- },
- toolbox: {
- feature: {
- saveAsImage: {}
- }
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: false,
- data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
- }
- ],
- yAxis: [
- {
- type: 'value'
- }
- ],
- series: [
- {
- name: '邮件营销',
- type: 'line',
- stack: '总量',
- areaStyle: { normal: {} },
- data: [120, 132, 101, 134, 90, 230, 210]
- },
- {
- name: '联盟广告',
- type: 'line',
- stack: '总量',
- areaStyle: { normal: {} },
- data: [220, 182, 191, 234, 290, 330, 310]
- },
- {
- name: '视频广告',
- type: 'line',
- stack: '总量',
- areaStyle: { normal: {} },
- data: [150, 232, 201, 154, 190, 330, 410]
- },
- {
- name: '直接访问',
- type: 'line',
- stack: '总量',
- areaStyle: { normal: {} },
- data: [320, 332, 301, 334, 390, 330, 320]
- },
- {
- name: '搜索引擎',
- type: 'line',
- stack: '总量',
- label: {
- normal: {
- show: true,
- position: 'top'
- }
- },
- areaStyle: { normal: {} },
- data: [820, 932, 901, 934, 1290, 1330, 1320]
- }
- ]
- };
-
- var barChartOption = {
- title: {
- text: option.title.text,
- subtext: '纯属虚构',
- x: 'center'
- },
- color: ['#3398DB'],
- tooltip: {
- trigger: 'axis',
- axisPointer: { // 坐标轴指示器,坐标轴触发有效
- type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
- }
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- data: option.xAxis[0].data,
- }
- ],
- yAxis: [
- {
- type: 'value'
- }
- ],
- series: [
- {
- name: '直接访问',
- type: 'bar',
- barWidth: '60%',
- data: [10, 52, 200, 334, 390, 330, 220]
- }
- ]
- };
-
- var pieChartOption = {
- title: {
- text: '某站点用户访问来源',
- subtext: '纯属虚构',
- x: 'center'
- },
- tooltip: {
- trigger: 'item',
- formatter: "{a} <br/>{b} : {c} ({d}%)"
- },
- legend: {
- orient: 'vertical',
- left: 'left',
- data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
- },
- series: [
- {
- name: '访问来源',
- type: 'pie',
- radius: '55%',
- center: ['50%', '60%'],
- data: [
- { value: 335, name: '直接访问' },
- { value: 310, name: '邮件营销' },
- { value: 234, name: '联盟广告' },
- { value: 135, name: '视频广告' },
- { value: 1548, name: '搜索引擎' }
- ],
- itemStyle: {
- emphasis: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ]
- };
-
- var chart = echarts.init(document.getElementById('lineChart'));
- chart.setOption(lineChartOption);
-
- var chart = echarts.init(document.getElementById('barChart'));
- chart.setOption(barChartOption);
-
- var chart = echarts.init(document.getElementById('pieChart'));
- chart.setOption(pieChartOption);
- }
- </script>
- </body>
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。