Commit 67a8fd1c by 胡悦

提交地图

1 parent 54326505
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2022-10-25 10:12:26
* @Description:
* @Author: huyue
* @Date: 2023-07-04 17:23:09
* @LastEditors: huyue
* @LastEditTime: 2023-07-04 18:05:08
* @FilePath: \dj-data-view\src\components\ViewTitle.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @LastEditTime: 2023-07-10 17:07:39
-->
<template>
<div>
<div>测试图</div>
<div id="demo" style="width: 100vw;height: 50vh"></div>
<div class="mapChart">
<h2 class="title-item">{{ title }}</h2>
<div id="demo" class="midtop"></div>
</div>
</template>
<script type="text/ecmascript-6">
<script>
import * as echarts from 'echarts'
import '@/utils/china.js'
export default {
name: 'Charts',
data() {
return {}
// mixins: [resize],
props: {
id: {
type: String,
default: ''
// required: true
},
chartData: {
type: Array,
default: () => [],
// required: true
},
title: {
type: String,
default: '',
// required: true
}
},
mounted() {
var chartDom = document.getElementById('demo')
var myChart = echarts.init(chartDom)
var option
const xAxisData = []
const data1 = []
const data2 = []
for (let i = 0; i < 10; i++) {
xAxisData.push('Class' + i)
data1.push(+(Math.random() * 2).toFixed(2))
data2.push(+(Math.random() * 5).toFixed(2))
data() {
return {
chart: null
}
var emphasisStyle = {
itemStyle: {
shadowBlur: 10,
shadowColor: 'rgba(0,0,0,0.3)'
},
watch: {
chartData: {
deep: true,
handler(val) {
this.setOptions(val)
}
}
option = {
legend: {
data: ['bar', 'bar2', 'line'],
left: '10%'
},
brush: {
toolbox: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
xAxisIndex: 0
},
toolbox: {
feature: {
magicType: {
type: ['stack']
},
dataView: {}
}
},
tooltip: {},
xAxis: {
data: xAxisData,
name: 'X Axis',
axisLine: { onZero: true },
splitLine: { show: false },
splitArea: { show: false }
},
yAxis: {},
grid: {
bottom: 100
},
series: [
{
name: 'bar',
type: 'bar',
stack: 'one',
emphasis: emphasisStyle,
data: data1,
label: {
show: true
},
itemStyle: {
barBorderRadius: [2, 2, 0, 0], // 柱体圆角
color: function(params) {
console.log(params)
const colorList = [
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF'],
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF'],
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF'],
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF'],
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF'],
['#22D8FF', '#5C56FF'],
['#2AD190', '#00B7DF']
]
var colorItem = colorList[params.dataIndex]
return new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{ // 代表渐变色从正上方开始
offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
color: colorItem[0]
}, // 柱图渐变色
{
offset: 1, // 指100%处的颜色
color: colorItem[1]
}]
)
}
}
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
methods: {
initChart() {
this.chart = echarts.init(document.getElementById('demo'))
this.setOptions(this.chartData)
this.chart.on('click', function (params) {
console.log(params.name)
})
},
setOptions(data = []) {
this.chart.setOption({
tooltip: {
trigger: 'item',
formatter: '{b}<br/>{c} (人)'
},
{
name: 'bar2',
type: 'bar',
stack: 'one',
label: {
show: true
},
emphasis: emphasisStyle,
data: data2,
itemStyle: {
barBorderRadius: [2, 2, 0, 0], // 柱体圆角
color: function(params) {
console.log(params)
const colorList = [
['#11627A', '#282F7A'],
['#145F4E', '#035972'],
['#11627A', '#282F7A'],
['#145F4E', '#035972'],
['#11627A', '#282F7A'],
['#145F4E', '#035972'],
['#11627A', '#282F7A'],
['#145F4E', '#035972'],
['#11627A', '#282F7A'],
['#145F4E', '#035972'],
['#11627A', '#282F7A'],
['#145F4E', '#035972']
]
var colorItem = colorList[params.dataIndex]
return new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{ // 代表渐变色从正上方开始
offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
color: colorItem[0]
}, // 柱图渐变色
{
offset: 1, // 指100%处的颜色
color: colorItem[1]
}]
)
}
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
dataView: { readOnly: false },
restore: {},
saveAsImage: {}
}
},
{
name: 'Dynamic Line',
type: 'line',
data: data2
}
]
}
myChart.on('brushSelected', function(params) {
var brushed = []
var brushComponent = params.batch[0]
for (var sIdx = 0; sIdx < brushComponent.selected.length; sIdx++) {
var rawIndices = brushComponent.selected[sIdx].dataIndex
brushed.push('[Series ' + sIdx + '] ' + rawIndices.join(', '))
}
myChart.setOption({
title: {
backgroundColor: '#333',
text: 'SELECTED DATA INDICES: \n' + brushed.join('\n'),
bottom: 0,
right: '10%',
width: 100,
visualMap: {
min: 800,
max: 50000,
text: ['High', 'Low'],
realtime: false,
calculable: true,
left: '5%',
bottom: '8%',
textStyle: {
fontSize: 12,
color: '#fff'
},
color: '#fff',
inRange: {
color: ['lightskyblue', 'yellow', 'orangered']
}
},
series: [
{
type: 'map',
map: 'china',
label: {
show: true,
color: 'yellow'
},
data
}
}
]
})
})
option && myChart.setOption(option)
}
}
}
</script>
<style scoped lang="scss">
.mapChart {
text-align: center;
width: 100%;
font-size: 12px;
font-weight: normal;
letter-spacing: 2px;
font-weight: normal;
overflow: hidden;
}
.midtop {
width: 99%;
height: 430px;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!