zoukankan      html  css  js  c++  java
  • Echarts、大屏动态折线图无状态加载

    直接上代码!!! 我这边需要wepstorket实时推送有部分代码可忽略
    <script>
    //按需引入
    import mySocket from '@/common/BigScreenSocket'
    import * as echarts from 'echarts/core'
    import { TitleComponent, ToolboxComponent, TooltipComponent, GridComponent, LegendComponent } from 'echarts/components'
    import { LineChart } from 'echarts/charts'
    import { CanvasRenderer } from 'echarts/renderers'
    import { color } from 'echarts/core'
    echarts.use([
        TitleComponent,
        ToolboxComponent,
        TooltipComponent,
        GridComponent,
        LegendComponent,
        LineChart,
        CanvasRenderer
    ])
    export default {
        name: 'Quantity',
        data () {
            const that = this
            return {
                totalNum: {},
                date: [],
                yieldRate: [],
                yieldIndex: [],
                echartsOption: {
                    color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
                    // title: {
                    //     text: '渐变堆叠面积图'
                    // },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
     
    
                        x: '55%',
                        y: '10%',
                        data: ['进水', '出水'],
                        textStyle: {
                            // fontSize: 18, // 字体大小
                            color: '#ffffff'// 字体颜色
                        }
                    },
                    // toolbox: {
                    //     feature: {
                    //         saveAsImage: {}
                    //     }
                    // },
                    grid: {
                        left: '3%',
                        right: '6%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: that.date,
                            splitLine: {
                                show: false,
                                lineStyle: {
                                    color: 'rgba(0,131,126,0.69)'
                                }
                            },
                            axisLabel: {
                                show: true
                            }
     
    
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0,131,126,0.69)'
                                }
                            },
                            // 刻度线
                            axisTick: {
                                show: false,
                                color: 'rgba(0,131,126,0.69)'
                            },
                            // 坐标轴
                            axisLine: {
                                show: true,
                                color: 'rgba(0,131,126,0.69)'
                            }
                        }
     
    
                    ],
                    series: [
                        {
                            name: '进水',
                            type: 'line',
                            stack: '总量',
                            smooth: true,
                            lineStyle: {
                                 1
                            },
                            showSymbol: false,
                            areaStyle: {
                                opacity: 0.4,
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(128, 255, 165)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(1, 191, 236)'
                                }])
                            },
                            emphasis: {
                                focus: 'series'
                            },
                            data: that.yieldRate
                            //  [140, 232, 101, 264, 90, 340, 250]
                        },
                        {
                            name: '出水',
                            type: 'line',
                            stack: '总量',
                            smooth: true,
                            lineStyle: {
                                 1
                            },
                            showSymbol: false,
                            areaStyle: {
                                opacity: 0.4,
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(0, 221, 255)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(77, 119, 255)'
                                }])
                            },
                            emphasis: {
                                focus: 'series'
                            },
                            data: that.yieldIndex
                            //  [120, 282, 111, 234, 220, 340, 310]
                        }
                    ]
                }
            }
        },
        mounted () {
            this.myChart = echarts.init(document.getElementById('quantity'), 'light') // 初始化echarts, theme为light
            this.myChart.setOption(this.echartsOption)// echarts设置初始化选项
            setInterval(this.changCharts, 10010) 
            this.MySocket()// 实时通信
        },
        methods: {
      //这个方法可以理解为接口,本次开发我们采用的实时通信,故需要对wepStorket封装,具体封装见下篇
            MySocket () {
                mySocket.getMsg((res) => {
                    this.totalNum = res.detectTimeRealCapacity
                })
            },
      //组要部分
            changCharts () {
                this.date = this.totalNum.xaxis
                this.yieldRate = this.totalNum.influents
                this.yieldIndex = this.totalNum.effluents
                // 重新将数组赋值给echarts选项
                this.echartsOption.xAxis[0].data = this.date
                this.echartsOption.series[0].data = this.yieldRate
                this.echartsOption.series[1].data = this.yieldIndex
                this.myChart.setOption(this.echartsOption)
            }
           
        }
    }
    </script>
  • 相关阅读:
    Oracle查询错误分析:ORA-01791:不是SELECTed表达式
    Java中DESKeySpec类
    linux发布项目
    mac下搭建cocos2d-x2.2.1版本android编译环境教程
    使用Eigen求解线性方程组
    视觉SLAM十四讲课后答案-ch1
    costmap_2d: obstacle_layer中关于激光雷达障碍物清除不干净的解决
    ch4 激光的前端配准算法一 —— ICP方法
    Project 'cv_bridge' specifies '/usr/include/opencv' as an include dir, which is not found.
    ch3 传感器数据处理II: 激光雷达运动畸变去除
  • 原文地址:https://www.cnblogs.com/huoshengmiao/p/14875669.html
Copyright © 2011-2022 走看看