|
@@ -7,161 +7,189 @@
|
|
|
|
|
|
<script>
|
|
|
export default {
|
|
|
- name: 'yearbasis',
|
|
|
+ name: "yearbasis",
|
|
|
data() {
|
|
|
return {
|
|
|
- seriesData1:[1,2,4,5,6,2,2,9,2,11,2,5],
|
|
|
- seriesData2:[4,2,4,5,4,7,5,9,2,5,4,8]
|
|
|
- }
|
|
|
- },
|
|
|
- components: {
|
|
|
- },
|
|
|
- created(){
|
|
|
+ seriesData1: [1, 2, 4, 5, 6, 2, 2, 9, 2, 11, 2, 5],
|
|
|
+ seriesData2: [4, 2, 4, 5, 4, 7, 5, 9, 2, 5, 4, 8],
|
|
|
+ isLine: true,
|
|
|
+ timer: "",
|
|
|
+ };
|
|
|
},
|
|
|
+ components: {},
|
|
|
+ created() {},
|
|
|
mounted() {
|
|
|
- this.drawChart()
|
|
|
+ this.drawChart();
|
|
|
+ this.timer && clearInterval(this.timer);
|
|
|
+ this.timer = setInterval(this.drawChart, 3500);
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ clearInterval(this.timer);
|
|
|
},
|
|
|
methods: {
|
|
|
drawChart() {
|
|
|
- const chartReady = this.$echarts.init(this.$refs.chart)
|
|
|
+ this.isLine = !this.isLine;
|
|
|
+ const chartReady = this.$echarts.init(this.$refs.chart);
|
|
|
const options = {
|
|
|
tooltip: {
|
|
|
- trigger: 'axis',
|
|
|
- axisPointer: {
|
|
|
- type: 'shadow'
|
|
|
+ trigger: "axis",
|
|
|
+ axisPointer: {
|
|
|
+ type: "shadow",
|
|
|
},
|
|
|
- formatter: '{b0}<br />{a0}: {c0} m³<br />{a1}: {c1} m³'
|
|
|
+ formatter: "{b0}<br />{a0}: {c0} m³<br />{a1}: {c1} m³",
|
|
|
},
|
|
|
grid: {
|
|
|
- top:'15%',
|
|
|
- left: '2%',
|
|
|
- right: '2%',
|
|
|
- bottom: '5%',
|
|
|
- containLabel: true
|
|
|
+ top: "15%",
|
|
|
+ left: "2%",
|
|
|
+ right: "2%",
|
|
|
+ bottom: "5%",
|
|
|
+ containLabel: true,
|
|
|
},
|
|
|
xAxis: [
|
|
|
{
|
|
|
- type: 'category',
|
|
|
- data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
|
|
|
+ type: "category",
|
|
|
+ data: [
|
|
|
+ "1月",
|
|
|
+ "2月",
|
|
|
+ "3月",
|
|
|
+ "4月",
|
|
|
+ "5月",
|
|
|
+ "6月",
|
|
|
+ "7月",
|
|
|
+ "8月",
|
|
|
+ "9月",
|
|
|
+ "10月",
|
|
|
+ "11月",
|
|
|
+ "12月",
|
|
|
+ ],
|
|
|
boundaryGap: false,
|
|
|
axisLine: {
|
|
|
lineStyle: {
|
|
|
- color: "rgba(255, 255, 255, 0.24)"
|
|
|
- }
|
|
|
+ color: "rgba(255, 255, 255, 0.24)",
|
|
|
+ },
|
|
|
},
|
|
|
axisLabel: {
|
|
|
- color: '#A4D9F9'
|
|
|
- }
|
|
|
- }
|
|
|
+ color: "#A4D9F9",
|
|
|
+ },
|
|
|
+ },
|
|
|
],
|
|
|
yAxis: [
|
|
|
{
|
|
|
- type: 'value',
|
|
|
+ type: "value",
|
|
|
axisLine: {
|
|
|
- show:false,
|
|
|
+ show: false,
|
|
|
lineStyle: {
|
|
|
- color: "rgba(255, 255, 255, 0.24)"
|
|
|
- }
|
|
|
+ color: "rgba(255, 255, 255, 0.24)",
|
|
|
+ },
|
|
|
},
|
|
|
- splitLine:{
|
|
|
- lineStyle:{
|
|
|
- color: "rgba(255, 255, 255, 0.24)"
|
|
|
- }
|
|
|
+ splitLine: {
|
|
|
+ lineStyle: {
|
|
|
+ color: "rgba(255, 255, 255, 0.24)",
|
|
|
+ },
|
|
|
},
|
|
|
axisLabel: {
|
|
|
- color: '#A4D9F9'
|
|
|
+ color: "#A4D9F9",
|
|
|
},
|
|
|
- }
|
|
|
+ },
|
|
|
],
|
|
|
- color: ['#20AEFF','#D7CB69'],
|
|
|
+ color: ["#20AEFF", "#D7CB69"],
|
|
|
legend: {
|
|
|
- data: ['今年','去年'],
|
|
|
- right:'0',
|
|
|
- textStyle:{
|
|
|
- color:'#A4D9F9'
|
|
|
- }
|
|
|
+ data: ["今年", "去年"],
|
|
|
+ right: "0",
|
|
|
+ textStyle: {
|
|
|
+ color: "#A4D9F9",
|
|
|
+ },
|
|
|
},
|
|
|
series: [
|
|
|
{
|
|
|
- name: '今年',
|
|
|
- type: 'bar',
|
|
|
+ name: "今年",
|
|
|
+ type: "bar",
|
|
|
data: this.seriesData2,
|
|
|
// smooth: true,
|
|
|
- barWidth:'36%',
|
|
|
+ barWidth: "36%",
|
|
|
itemStyle: {
|
|
|
color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
- { offset: 0, color: '#20AEFF' },
|
|
|
- { offset: 0.5, color: '#148DF9' },
|
|
|
- { offset: 1, color: '#0373F1' }
|
|
|
- ])
|
|
|
+ { offset: 0, color: "#20AEFF" },
|
|
|
+ { offset: 0.5, color: "#148DF9" },
|
|
|
+ { offset: 1, color: "#0373F1" },
|
|
|
+ ]),
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
- name: '去年',
|
|
|
- type: 'line',
|
|
|
+ name: "去年",
|
|
|
+ type: "line",
|
|
|
data: this.seriesData1,
|
|
|
smooth: true,
|
|
|
- }
|
|
|
- ]
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ if(this.isLine){
|
|
|
+ options.series[0].type='line'
|
|
|
+ options.series[0].smooth=true
|
|
|
+ }else{
|
|
|
+ options.series[0].type='bar'
|
|
|
}
|
|
|
- chartReady.setOption(options)
|
|
|
+ // options.series.forEach((item) => {
|
|
|
+ // item.type = this.isLine ? "bar" : "line";
|
|
|
+ // });
|
|
|
+ chartReady.setOption(options);
|
|
|
|
|
|
//自定义缩放
|
|
|
window.addEventListener("resize", () => {
|
|
|
- if(chartReady){
|
|
|
- chartReady.resize()
|
|
|
+ if (chartReady) {
|
|
|
+ chartReady.resize();
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
- }
|
|
|
-}
|
|
|
+ },
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
- .yearbasis{
|
|
|
- width: calc(100% - 16px);
|
|
|
- height: calc(100% - 16px);
|
|
|
- position: relative;
|
|
|
- padding: 8px;
|
|
|
- // border: 1px red solid;
|
|
|
+.yearbasis {
|
|
|
+ width: calc(100% - 16px);
|
|
|
+ height: calc(100% - 16px);
|
|
|
+ position: relative;
|
|
|
+ padding: 8px;
|
|
|
+ // border: 1px red solid;
|
|
|
|
|
|
- .title{
|
|
|
- width: 150px;
|
|
|
- height: 16px;
|
|
|
- font-size: 16px;
|
|
|
- font-weight: 400;
|
|
|
- padding-left: 20px;
|
|
|
- color: #22AFFF;
|
|
|
- line-height: 16px;
|
|
|
- text-shadow: 0px 4px 5px rgba(1, 18, 32, 0.7);
|
|
|
- position:absolute;
|
|
|
- // border: 1px red solid;
|
|
|
+ .title {
|
|
|
+ width: 150px;
|
|
|
+ height: 16px;
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 400;
|
|
|
+ padding-left: 20px;
|
|
|
+ color: #22afff;
|
|
|
+ line-height: 16px;
|
|
|
+ text-shadow: 0px 4px 5px rgba(1, 18, 32, 0.7);
|
|
|
+ position: absolute;
|
|
|
+ // border: 1px red solid;
|
|
|
|
|
|
- &::after {
|
|
|
- content: '';
|
|
|
- // height: 2px;
|
|
|
- // background-color: #fe0000;
|
|
|
- // // width: 50px;
|
|
|
- // position: absolute;
|
|
|
- // bottom: 0;
|
|
|
- // left: 0px;
|
|
|
- // right: 0px;
|
|
|
- content:"";
|
|
|
- width: 14px;
|
|
|
- height: 14px;
|
|
|
- background: #28ACFF;
|
|
|
- box-shadow: 0px 5px 5px 0px rgba(0, 9, 16, 0.76);
|
|
|
- position:absolute;
|
|
|
- top:0;
|
|
|
- left:0;
|
|
|
- transform: rotateZ(45deg);
|
|
|
- }
|
|
|
+ &::after {
|
|
|
+ content: "";
|
|
|
+ // height: 2px;
|
|
|
+ // background-color: #fe0000;
|
|
|
+ // // width: 50px;
|
|
|
+ // position: absolute;
|
|
|
+ // bottom: 0;
|
|
|
+ // left: 0px;
|
|
|
+ // right: 0px;
|
|
|
+ content: "";
|
|
|
+ width: 14px;
|
|
|
+ height: 14px;
|
|
|
+ background: #28acff;
|
|
|
+ box-shadow: 0px 5px 5px 0px rgba(0, 9, 16, 0.76);
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ transform: rotateZ(45deg);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- .line{
|
|
|
- width: 100%;
|
|
|
- height: 100%;
|
|
|
- // border: 1px red solid;
|
|
|
- }
|
|
|
+ .line {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ // border: 1px red solid;
|
|
|
}
|
|
|
+}
|
|
|
</style>
|