2020-03-17 18:27:46 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="chart-room">
|
2020-03-23 18:20:19 +08:00
|
|
|
<loading ref="loading"></loading>
|
2020-03-17 18:27:46 +08:00
|
|
|
|
2020-03-23 18:20:19 +08:00
|
|
|
<div class="chart-header">{{chartTitle}}</div>
|
|
|
|
|
|
|
|
|
|
<div class="chart-body" ref="chartBody" :id="chartId" style="height: 95%"></div>
|
2020-03-17 18:27:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import echarts from 'echarts';
|
|
|
|
|
import chartDataFormat from "../../../charts/chartDataFormat";
|
|
|
|
|
import loading from "../../../common/loading";
|
2020-03-23 18:20:19 +08:00
|
|
|
import uuidv1 from "uuid/v1";
|
2020-03-17 18:27:46 +08:00
|
|
|
import chartConfig from './chartConfig'
|
|
|
|
|
export default {
|
|
|
|
|
name: "chart",
|
2020-03-23 18:20:19 +08:00
|
|
|
components:{
|
|
|
|
|
'loading':loading,
|
|
|
|
|
},
|
|
|
|
|
props:{
|
2020-03-24 13:19:18 +08:00
|
|
|
chartTitle:{type:String},
|
|
|
|
|
chartType:{type:String,default:'line'},
|
2020-03-30 21:09:34 +08:00
|
|
|
map:{}
|
2020-03-23 18:20:19 +08:00
|
|
|
},
|
2020-03-17 18:27:46 +08:00
|
|
|
data(){
|
|
|
|
|
return {
|
2020-03-23 18:20:19 +08:00
|
|
|
chart:null,
|
|
|
|
|
option:{},
|
|
|
|
|
chartId:new uuidv1()+'-'+new Date().getTime(),
|
2020-03-17 18:27:46 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
2020-03-24 20:25:16 +08:00
|
|
|
|
2020-03-17 18:27:46 +08:00
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
|
2020-03-31 20:08:33 +08:00
|
|
|
modifyOption:function(target,name,obj){
|
|
|
|
|
if(this.option){
|
|
|
|
|
this.option=chartConfig.getOption(this.chartType);
|
2020-03-23 18:20:19 +08:00
|
|
|
}
|
2020-03-31 20:08:33 +08:00
|
|
|
this.$set(this.option[target],name,obj)
|
2020-03-23 18:20:19 +08:00
|
|
|
},
|
|
|
|
|
setSeries:function(series){
|
|
|
|
|
if(!this.chart){
|
|
|
|
|
this.chart=echarts.init(document.getElementById(this.chartId));
|
|
|
|
|
}
|
2020-03-24 20:25:16 +08:00
|
|
|
this.series=series;
|
2020-03-24 13:19:18 +08:00
|
|
|
if(this.chartType == 'map'){
|
2020-03-30 21:09:34 +08:00
|
|
|
if(this.map){
|
|
|
|
|
echarts.registerMap(this.map.name,this.map.geoJson);
|
|
|
|
|
chartConfig.setMap(this.map.name);
|
|
|
|
|
}else{
|
|
|
|
|
console.error('map chart need map data');
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 13:19:18 +08:00
|
|
|
}
|
2020-03-31 20:08:33 +08:00
|
|
|
if(this.option){
|
|
|
|
|
this.option=chartConfig.getOption(this.chartType);
|
|
|
|
|
}
|
2020-03-24 20:25:16 +08:00
|
|
|
this.$set(this.option,'series',this.series);
|
2020-03-31 20:08:33 +08:00
|
|
|
/*if(this.chartType == 'line'){
|
2020-03-24 20:25:16 +08:00
|
|
|
this.$set(this.option.tooltip,'formatter',this.tooltipFormatter);
|
|
|
|
|
this.$set(this.option.tooltip,'position',this.tooltipPosition);
|
|
|
|
|
this.$set(this.option.yAxis,'formatter',this.yAxisFormatter);
|
2020-03-31 20:08:33 +08:00
|
|
|
}*/
|
2020-03-24 20:25:16 +08:00
|
|
|
|
2020-03-23 18:20:19 +08:00
|
|
|
this.chart.clear();
|
|
|
|
|
this.chart.setOption(this.option)
|
|
|
|
|
},
|
2020-03-25 16:27:00 +08:00
|
|
|
resizeChart:function(width,height){
|
|
|
|
|
if(this.chart){
|
|
|
|
|
this.chart.resize({width:width,height:height});
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-03-23 18:20:19 +08:00
|
|
|
startLoading:function(){
|
|
|
|
|
this.$refs.loading.startLoading();
|
|
|
|
|
},
|
|
|
|
|
endLoading:function(){
|
|
|
|
|
this.$refs.loading.endLoading();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.chart=echarts.init(document.getElementById(this.chartId));
|
2020-03-17 18:27:46 +08:00
|
|
|
},
|
|
|
|
|
watch:{
|
|
|
|
|
|
2020-03-23 18:20:19 +08:00
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
if(this.chart){
|
|
|
|
|
this.chart.clear();
|
|
|
|
|
}
|
2020-03-17 18:27:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2020-03-23 18:20:19 +08:00
|
|
|
.chart-room{
|
|
|
|
|
width: 95%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
2020-03-17 18:27:46 +08:00
|
|
|
</style>
|