Commit 72e0c4af by liwk

commit

1 parent 29f3ad62
const Map = {
'北京': 11,
'天津': 12,
'河北': 13,
'山西': 14,
'内蒙古': 15,
'辽宁': 21,
'吉林': 22,
'黑龙江': 23,
'上海': 31,
'江苏': 32,
'浙江': 33,
'安徽': 34,
'福建': 35,
'江西': 36,
'山东': 37,
'河南': 41,
'湖北': 42,
'湖南': 43,
'广东': 44,
'广西': 45,
'海南': 46,
'重庆': 50,
'四川': 51,
'贵州': 52,
'云南': 53,
'西藏': 54,
'陕西': 61,
'甘肃': 62,
'青海': 63,
'宁夏': 64,
'新疆': 65,
'台湾': 71,
'香港': 81,
'澳门': 82
}
export default Map
\ No newline at end of file \ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
...@@ -15,12 +15,12 @@ export default { ...@@ -15,12 +15,12 @@ export default {
return { return {
canvas: null, canvas: null,
index: 6, index: 6,
labels:[], labels: [],
values:[] values: []
} }
}, },
props: { props: {
data: null, data: Array,
days: Array, days: Array,
type: { type: {
type: String, type: String,
...@@ -37,7 +37,7 @@ export default { ...@@ -37,7 +37,7 @@ export default {
}, },
watch: { watch: {
'days' (newVal, oldVal) { 'days' (newVal, oldVal) {
if (newVal) { if (newVal.length > 0) {
this.createdCanvas() this.createdCanvas()
} }
} }
...@@ -47,13 +47,17 @@ export default { ...@@ -47,13 +47,17 @@ export default {
}, },
methods: { methods: {
createdCanvas () { createdCanvas () {
// let days = [] if (this.canvas) {
// let data = [] this.labels = []
this.values = []
this.canvas.clear()
}
this.index = this.days.length < this.index ? this.days.length : this.index
for (let i = 0; i < this.index; i++) { for (let i = 0; i < this.index; i++) {
this.labels.push(this.days[i]) this.labels.push(this.days[i])
this.values.push(this.data[i]) this.values.push(this.data[i])
} }
let canvas = echarts.init(this.$refs.canvas) this.canvas = echarts.init(this.$refs.canvas)
let options = { let options = {
xAxis: { xAxis: {
type: 'category', type: 'category',
...@@ -101,7 +105,6 @@ export default { ...@@ -101,7 +105,6 @@ export default {
series: [ series: [
{ {
data: this.values, data: this.values,
name: '出行次数',
type: this.type, type: this.type,
barWidth: '60px', barWidth: '60px',
smooth: true, smooth: true,
...@@ -167,13 +170,15 @@ export default { ...@@ -167,13 +170,15 @@ export default {
data: this.values data: this.values
}) })
} }
canvas.setOption(options) this.canvas.setOption(options)
if (this.days.length > 6) {
setInterval(() => { setInterval(() => {
this.moveCanvas(options, canvas) this.moveCanvas(options)
}, 5 * 1000) }, this.speed * 1000)
}
}, },
moveCanvas (options, canvas) { moveCanvas (options) {
if (this.index > this.days.length-1) { if (this.index > this.days.length - 1) {
this.index = 0 this.index = 0
} }
this.labels.shift() this.labels.shift()
...@@ -186,7 +191,7 @@ export default { ...@@ -186,7 +191,7 @@ export default {
options.xAxis.data = this.labels options.xAxis.data = this.labels
options.series[0].data = this.values options.series[0].data = this.values
this.index++ this.index++
canvas.setOption(options) this.canvas.setOption(options)
} }
}, },
} }
......
...@@ -19,16 +19,30 @@ ...@@ -19,16 +19,30 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import china from '@p/map/china.json' import china from '@p/map/china.json'
import axios from 'axios'
import "echarts-gl" import "echarts-gl"
import { request } from 'https' import { request } from 'https'
import map_code from '@p/map/mapId.js'
Array.prototype.max = function () {
return Math.max.apply({}, this)
}
Array.prototype.min = function () {
return Math.min.apply({}, this)
}
export default { export default {
name: 'GlMap', name: 'GlMap',
data () { data () {
return { return {
mapName: 'china', mapName: 'china',
map: null, map: null,
visualMapRange: [],
pid: null,
options: { options: {
visualMap: {
show: false,
inRange: {
color: ['#1DE6EE', '#0B7FE1']
}
},
tooltip: { tooltip: {
position: 'top', position: 'top',
}, },
...@@ -38,10 +52,10 @@ export default { ...@@ -38,10 +52,10 @@ export default {
name: 'china', name: 'china',
selectedMode: "single",//地图高亮单选 selectedMode: "single",//地图高亮单选
boxDepth: 90,//地图倾斜度 boxDepth: 90,//地图倾斜度
regionHeight: 8,//地图高度 regionHeight: 2,//地图高度
map: 'china', map: 'china',
itemStyle: { itemStyle: {
color: "#40a7ee", // color: "#40a7ee",
borderWidth: 1,//分界线wdith borderWidth: 1,//分界线wdith
borderColor: "#6ce3ec",//分界线颜色 borderColor: "#6ce3ec",//分界线颜色
}, },
...@@ -84,39 +98,91 @@ export default { ...@@ -84,39 +98,91 @@ export default {
} }
} }
] ]
} },
mapData: []
} }
}, },
mounted () { mounted () {
this.map = echarts.init(this.$refs.map) this.map = echarts.init(this.$refs.map)
this.map.showLoading() this.map.showLoading()
this.getData(() => {
this.chinaConfigure(this.mapName, china) this.chinaConfigure(this.mapName, china)
this.map.on('click', even => { this.map.on('click', even => {
console.log(even)
if (this.mapName == 'china') { if (this.mapName == 'china') {
this.pid = map_code[even.name]
this.$emit('mapclick', this.pid)
this.$refs.map.classList.add('change') this.$refs.map.classList.add('change')
this.mapName = even.name this.mapName = even.name
axios.get(`/map/province/${even.name}.json`).then(res => { this.axios.get(`/map/province/${even.name}.json`).then(res => {
this.map.clear() this.map.clear()
this.mapData = []
this.visualMapRange = []
this.getData(() => {
this.chinaConfigure(even.name, res.data) this.chinaConfigure(even.name, res.data)
}) })
})
} }
}) })
this.map.on('mouseover', even => {
console.log(even)
}) })
}, },
methods: { methods: {
/**获取全国 省份数据 */
getData (callBack) {
this.axios.get(`${this.domain}/screen/user/total_group_by_province`, {
params: {
pid: this.pid
}
}).then(res => {
console.log('获取全国省份数据', res)
let data = res.data.data
if (this.mapName == 'china') {
for (const key in map_code) {
data.forEach(el => {
if (el.prov_code == map_code[key]) {
this.mapData.push({
name: key,
value: el.total_user
})
this.visualMapRange.push(el.total_user)
}
})
}
} else {
data.forEach(el => {
this.mapData.push({
name: el.city_name,
value: el.total_user
})
this.visualMapRange.push(el.total_user)
})
}
return callBack()
})
},
back () { back () {
this.map.clear()
this.$refs.map.classList.add('change') this.$refs.map.classList.add('change')
this.mapName = 'china' this.mapName = 'china'
this.map.clear() this.pid = null
this.mapData = []
this.visualMapRange = []
this.getData(() => {
this.chinaConfigure(this.mapName, china) this.chinaConfigure(this.mapName, china)
this.$emit('mapclick', this.pid)
})
}, },
chinaConfigure (mapName, data) { chinaConfigure (mapName, data) {
this.map.hideLoading() this.map.hideLoading()
echarts.registerMap(mapName, data) echarts.registerMap(mapName, data)
window.onresize = this.map.resize window.onresize = this.map.resize
let options = this.options let options = this.options
let max = this.visualMapRange.max()
let min = this.visualMapRange.min()
options.visualMap.min = min
options.visualMap.max = max
options.series[0].data = this.mapData
options.series[0].name = options.series[0].map = mapName options.series[0].name = options.series[0].map = mapName
this.map.setOption(options) this.map.setOption(options)
setTimeout(() => { setTimeout(() => {
......
...@@ -14,26 +14,34 @@ ...@@ -14,26 +14,34 @@
export default { export default {
name: 'Rose', name: 'Rose',
props: { props: {
data: null list: {
type: Array,
default: []
}
}, },
data () { data () {
return { return {
roseColors: ['#773ae6', '#372ef0', '#5242f3', '#0060ff', '#0096ff', '#00e5dd', '#36a8ff', '#0078f4'] roseColors: ['#773ae6', '#372ef0', '#5242f3', '#0060ff', '#0096ff', '#00e5dd', '#36a8ff', '#0078f4'],
canvas: null
} }
}, },
mounted () { watch: {
'list' (n, o) {
if (n.length > 0) {
this.createdCanvas() this.createdCanvas()
}
}
}, },
methods: { methods: {
createdCanvas () { createdCanvas () {
if (this.canvas) this.canvas.clear()
let roseColors = [] let roseColors = []
let data = this.data.sort(function (a, b) { let data = this.list
return a.value - b.value let sum = data.reduce((pre, next) => pre + Number(next.value), 0)
})
data.forEach((e, i) => { data.forEach((e, i) => {
roseColors.push(this.roseColors[8 - data.length + i]) roseColors.push(this.roseColors[8 - data.length + i])
}) })
let canvas = echarts.init(this.$refs.data) this.canvas = echarts.init(this.$refs.data)
let options = { let options = {
series: [{ series: [{
type: 'pie', type: 'pie',
...@@ -41,19 +49,21 @@ export default { ...@@ -41,19 +49,21 @@ export default {
center: ['50%', 120], center: ['50%', 120],
color: roseColors, color: roseColors,
data: data, data: data,
minAngle: 270,
roseType: 'radius', roseType: 'radius',
label: { label: {
normal: { normal: {
show: false, show: false,
formatter: ['{b|{b}}', '{c|{c}}'].join('\n'), formatter: ['{b|{b}}', '{d|{d}%}'].join('\n'),
rich: { rich: {
c: { d: {
color: '#fff', color: '#fff',
fontSize: 16, fontSize: 16,
}, },
b: { b: {
color: '#fff', color: '#fff',
fontSize: 16, fontSize: 16,
lineHeight: 20
}, },
}, },
} }
...@@ -76,22 +86,23 @@ export default { ...@@ -76,22 +86,23 @@ export default {
} }
}] }]
} }
canvas.on('mouseover', params => { let option = options.series[0]
options.series[0].data[params.dataIndex].labelLine = options.series[0].data[params.dataIndex].label = { this.canvas.on('mouseover', params => {
option.data[params.dataIndex].labelLine = option.data[params.dataIndex].label = {
normal: { normal: {
show: true show: true
} }
} }
canvas.setOption(options) this.canvas.setOption(options)
}) })
canvas.on('mouseout', params => { this.canvas.on('mouseout', params => {
options.series[0].data[params.dataIndex].label = options.series[0].data[params.dataIndex].labelLine = { option.data[params.dataIndex].label = option.data[params.dataIndex].labelLine = {
normal: { normal: {
show: false show: false
} }
} }
}) })
canvas.setOption(options) this.canvas.setOption(options)
} }
} }
} }
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
<div> <div>
<img src="~@a/man.png"> <img src="~@a/man.png">
男 男
<span>{{list.man.percent}}</span> <span>{{manPercent}}</span>
</div> </div>
<div style="padding-left:130px;"> <div style="padding-left:130px;">
<img src="~@a/women.png"> <img src="~@a/women.png">
女 女
<span>{{list.women.percent}}</span> <span>{{womenPercent}}</span>
</div> </div>
</div> </div>
<div <div
...@@ -25,21 +25,47 @@ export default { ...@@ -25,21 +25,47 @@ export default {
name: 'User', name: 'User',
data () { data () {
return { return {
labelData: ['00后', '90后', '80后', '70后', '60后'] labelData: ['00后', '90后', '80后', '70后', '60后'],
manPercent: '0%',
womenPercent: '0%'
} }
}, },
props: { props: {
list: null list: {
type: Object,
default: {}
}
}, },
mounted () { mounted () {
this.createdCanvas()
},
watch: {
'list' (n, o) {
if (n) {
let data = n
let female = n.women.total
let male = n.man.total
let womenPercent = (female / (male + female) * 100).toFixed(1)
let manPercent = 100 - womenPercent
this.manPercent = `${manPercent}%`
this.womenPercent = `${womenPercent}%`
this.createdCanvas(male, female)
}
}
}, },
methods: { methods: {
createdCanvas () { createdCanvas (male, female) {
let obj = this.list
let manData = [] let manData = []
this.list.man.data.forEach(e => { let womenData = []
obj.man.data.forEach(e => {
e = (e / male * 100).toFixed(1)
manData.push(e * -1) manData.push(e * -1)
}) })
obj.women.data.forEach(e => {
e = (e / female * 100).toFixed(1)
womenData.push(e)
})
let canvas = echarts.init(this.$refs.data) let canvas = echarts.init(this.$refs.data)
let options = { let options = {
xAxis: [{ xAxis: [{
...@@ -170,12 +196,10 @@ export default { ...@@ -170,12 +196,10 @@ export default {
show: true, show: true,
formatter: val => { formatter: val => {
let value = 0 let value = 0
let sum = 0 manData.forEach((e, index) => {
this.list.man.data.forEach((e, index) => {
sum = sum + e
if (index == val.dataIndex) value = e if (index == val.dataIndex) value = e
}) })
return ((value * -1) / (sum * -1) * 100).toFixed(2) + '%' return `${value * -1}%`
} }
}, },
itemStyle: { itemStyle: {
...@@ -203,7 +227,7 @@ export default { ...@@ -203,7 +227,7 @@ export default {
borderColor: '#333', borderColor: '#333',
} }
}, },
data: this.list.women.data data: womenData
}, },
{ {
name: 'womenBorder', name: 'womenBorder',
...@@ -219,12 +243,10 @@ export default { ...@@ -219,12 +243,10 @@ export default {
offset: [36, 0], offset: [36, 0],
formatter: (val, index) => { formatter: (val, index) => {
let value = '' let value = ''
let sum = 0 womenData.forEach((e, index) => {
this.list.women.data.forEach((e, index) => {
sum = sum + e
if (index == val.dataIndex) value = e if (index == val.dataIndex) value = e
}) })
return (value / sum * 100).toFixed(2) + '%' return `${value}%`
} }
}, },
itemStyle: { itemStyle: {
......
import Vue from 'vue' import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import components from '@c/index.js' import components from '@c/index.js'
import axios from 'axios'
const domain = 'http://192.168.2.222:7001'
Vue.prototype.axios = axios
Vue.prototype.domain = domain
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(components) Vue.use(components)
new Vue({ new Vue({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!