<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>换乘分析</title>
<meta name="renderer" content="webkit">
<#include "/header.html">
<style>
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
html, body {
width: 100%;
height: 100%;
background-color: #ffffff;
margin: 0 auto;
padding: 0;
border: 0;
}
th {
text-align:center;
vertical-align:middle
}
#rrapp .main>div{
float: left;
}
</style>
</head>
<body>
<div id="rrapp">
<div class="grid-btn">
<!-- 查询-->
<div class="form-group col-sm-2" style="margin-right: 10px; margin-left: 3%;">
<div class="input-bor" style="width: 225px; line-height: 26px">
年份查询:<input class="" style="width: 145px;height: 22px;border: none;text-align: left;" id="dateYear" v-model="dateYear" class="select01" type="text" readonly placeholder="请选择" @click.stop="datePick">
</div>
</div>
<div class="form-group col-sm-2">
<div class="input-bor" style="width: 225px; line-height: 27px">
线路:
<select class="select01" style="width: 145px;" v-model="lineNumber" @change="lineNum">
<option value="">请选择</option>
<option value=1>1号线</option>
<option value=2>2号线</option>
<option value=3>3号线</option>
<option value=4>4号线</option>
<option value=5>5号线</option>
<option value=6>6号线</option>
<option value=7>7号线</option>
<option value=8>8号线</option>
<option value=9>9号线</option>
<option value=10>10号线</option>
<option value=11>11号线</option>
</select>
</div>
</div>
<div class="form-group col-sm-2" style="margin-left: 20px">
<a class="btn btn-warning" @click.stop="clearall" style="display: inline;">重置</a>
</div>
</div>
<div class="main">
<!-- 表格-->
<div class="layui-form-item" style="margin: 5% 0 2.5% 5%;">
<table class="gridtable">
<tr align="center">
<th>时间(月)</th>
<th>地铁换乘线路人数(万人)</th>
<th>地铁公交换乘人数(万人)</th>
</tr>
<tr align="center" v-for="item in list" key="item.id">
<td>{{item.year}}年{{item.month}}月</td>
<td>{{item.transferMetroNum}}</td>
<td>{{item.transferBusNum}}</td>
</tr>
</table>
</div>
<!-- echart图表-->
<div style="width: 55%; height: 420px; padding: 20px 0 20px 20px">
<div id="echartBar" style="width: 100%; height: 375px"></div>
</div>
</div>
</div>
<script type="text/javascript" src="${request.contextPath}/statics/libs/echarts.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/statics/libs/jquery.raty.js"></script>
<script type="text/javascript" src="${request.contextPath}/statics/plugins/layui/lay/laydate/laydate.js"></script>
<script type="text/javascript" src="${request.contextPath}/statics/js/modules/klyyfx/hcfx.js"></script>
</body>
</html>
var vm = new Vue({
el:'#rrapp',
data:{
dateYear: new Date().getFullYear(), // 年份查询
lineNumber: 1, // 线路查询
list: '', // 表格数据,
// chartsList: '' // 图表数据
},
mounted() {
this.initPage()
},
created() {
},
methods: {
initPage() {
this.chartData()
this.getList()
},
// 月选择器
datePick() {
var _this = this
laydate.render({
elem: '#dateYear',
type: 'year',
trigger: 'click',
done: function(value, date){
vm.dateYear = value
_this.getList()
}
})
},
// 获取首页数据
getList() {
var _this = this
request('transfer/getList', {
data: {
line : _this.lineNumber,
year: _this.dateYear
},
success: function(res) {
_this.list = res
_this.chartData (res)
// console.log('首页数据' ,_this.list,)
}
})
},
// 重置
clearall() {
vm.dateYear = new Date().getFullYear()
vm.lineNumber = 1
vm.getList()
},
// 路线查询
lineNum () {
vm.getList()
},
// 图表数据
chartData (res) {
console.log(res,"res11232322");
var objChart = {
xAxis: [],
year: '',
colors: ['#2296e7','#0c7d22'],
legendName: ['轨网地铁换乘客流占比(%)','轨网公交换乘客流占比(%)'],
data1: [], // 地铁换乘人数占比
data2: [], // 公交换乘人数占比
}
res = res || []
res.map(function (item) {
objChart.xAxis.push(item.month + '月')
objChart.year = item.year
objChart.data1.push(parseFloat((item.transferMetroNum / (item.transferMetroNum + item.transferBusNum) * 100).toFixed(1)))
objChart.data2.push(parseFloat((item.transferBusNum / (item.transferMetroNum + item.transferBusNum) * 100).toFixed(1)))
})
this.initChart('echartBar', objChart)
// console.log(objChart.data1)
// console.log(objChart.data2)
// console.log(objChart.year)
},
// 图表展示
initChart (id, configs) {
configs = configs || {}
var option = {
title: {
show: true,
text: configs.year + '年轨网换乘客流占比',
x: 'center'
},
color: configs.colors, // 颜色
tooltip: { // 提示框
trigger: 'axis', // 触发方式
axisPointer: {
type: 'shadow' // 阴影显示器
}
},
legend: { // 标题
show: true, // 显示
data: configs.legendName,
bottom: "0%"
},
grid: { // 图表跟容器的间距
show: true,
// left: '3%',
// right: '4%',
bottom: '20%',
// containLabel: true
},
xAxis: {
type: 'category',
data: configs.xAxis,
axisTick: {
show: false
}
},
yAxis: {
min: 0, // 最小值
max: 100, // 最大值
show: true,
axisLabel:{
formatter:'{value} %'
},
splitLine: {
show: true
// lineStyle: { // 刻度线颜色
// color: '#4c9bfd'
// }
},
axisLine: {
show: false // 去除轴线
},
axisTick: {
show: false //去除刻度线
},
type: 'value'
},
// series: {
// type: 'bar',
// name: configs.legendName,
// barWidth: 15,
// label: {
// show: true,
// position: 'top',
// fontWeight: 28,
// color: '#000000',
// formatter: '{c}'
// },
// data: configs.data
// }
series: [
{
type: 'bar',
barGap: '0%', // 清除个多个柱子之间的空隙
name: configs.legendName[0],
data: configs.data1
},
{
type: 'bar',
barGap: '0%',
name: configs.legendName[1],
data: configs.data2
},
]
}
var myChart = echarts.getInstanceByDom(document.getElementById(id));
if (myChart === undefined) {
myChart = echarts.init(document.getElementById(id));
}else{
myChart.clear(myChart)
}
myChart.setOption(option, true);
}
}
})
vue结合echarts柱状图,渲染
最新推荐文章于 2023-06-13 17:40:54 发布