123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <template>
- <div :id="'chart-sewage-line-' + lineConfig.id" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- import { mapState } from 'vuex'
- export default {
- name: "ChartSewageLine",
- computed: {
- ...mapState(['color'])
- },
- props: {
- lineConfig: {
- type: Object,
- default: function () {
- return {
- id: 0,
- time: [],
- data: [],
- name: '默认',
- unit: '%'
- }
- }
- }
- },
- watch: {
- color(newVal) {
- if(newVal) {
- this.myChart.clear();
- this.init()
- }
- }
- },
- data() {
- return {
- myChart: null
- }
- },
- methods: {
- init() {
- // 时间
- let dataAxis = this.lineConfig.time;
- let start = dataAxis.length - 12;
- let end = dataAxis.length - 1;
- // 数据
- let data = this.lineConfig.data;
- // 单位
- let unit = this.lineConfig.unit;
- // 名称
- let name = this.lineConfig.name;
- let options = {
- title: {
- text: name,
- top: "5%",
- left: '2%',
- textStyle: {
- color: this.color,
- fontSize: 16,
- fontWeight: 300,
- },
- padding: 5,
- },
- tooltip: {
- trigger: 'axis',
- },
- color: [this.color],
- dataZoom: [{
- type: 'inside',
- startValue: start,
- endValue: end,
- show: false
- // zoomOnMouseWheel: false,
- // zoomLock: true,
- }],
- // dataZoom: [
- //
- // {
- // type: 'slider',
- // startValue: start,
- // endValue:end,
- // zoomOnMouseWheel: false,
- // zoomLock: true,
- // },
- // {
- // type: 'inside'
- // },
- // ],
- xAxis: [
- {
- type: 'category',
- data: dataAxis,
- axisPointer: {
- type: 'shadow'
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#6e7079',
- }
- },
- axisTick:{
- show:false
- },
- }
- ],
- yAxis: [
- {
- type: 'value',
- name: '近7天统计',
- axisLabel: {
- formatter: `{value}${unit}`
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: '#6e7079',
- }
- },
- axisTick:{
- show:false
- },
- }
- ],
- series: [
- {
- name: name,
- type: 'line',
- // stack: 'Total',
- smooth: true,
- areaStyle: {},
- emphasis: {
- focus: 'series'
- },
- itemStyle : {
- color: this.color,
- borderColor: this.color,
- normal: {
- label : {
- show: true,
- textStyle: {
- fontSize: 14
- }
- }
- }
- },
- data: data
- }
- ]
- }
- this.myChart.setOption(options)
- }
- },
- mounted() {
- this.myChart = this.$echarts.init(document.getElementById('chart-sewage-line-' + this.lineConfig.id));
- this.init()
- }
- }
- </script>
- <style scoped>
- </style>
|