• echart.js组件编写


    1.传参

    <area-chart :chartdata='monitorTimes' :datatype='typeSelected' :dataX = '"tid"'  :types='types' ></area-chart>

    由于我的图表不同数据有不同的颜色,所以我传了一个typeSelected

    组件代码

    <template>
        <div class='chart__wrapper'></div>
    </template>
    <script>
        import echarts from 'echarts'
        export default {
            props: ['chartdata', 'datatype', 'dataX', 'types'],
            data() {
                return {
                    myChart: null
                }
            },
            methods: {
    
            },
            created:function() {
                
            },
            mounted: function() {
                let  _color = ['#CF6066','#27727B','#FCCE10','#E87C25','#B5C334'];
                this.myChart=echarts.init(this.$el);
                
                let seriesData = this.chartdata.map(o=>{
                    return o[this.datatype];
                })
                let color =_color[this.types.findIndex(o=> o.id == this.datatype )];
                //console.log(this.chartdata)
                let seriesX=this.chartdata.map(o=>{
                    return o[this.dataX]
                })
                //console.log("ss",seriesX)
                
                this.myChart.setOption({
                    tooltip: {
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: seriesX
                    },
                    yAxis: {
                        
                    },
                    series: [{
                        data: seriesData,//数据内容数组
                        type: 'line',
                        smooth: false,
                        lineStyle:{
                            normal:{
                                color:color
                            }
                        },
                        areaStyle:{
                            normal:{
                                color:color
                            }
                        }
                    }]
                })
                window.addEventListener('resize', this.myChart.resize);
            },
            beforeDestroy: function () {
                window.removeEventListener('resize', this.myChart.resize)
            }
        }
    </script>
    <style lang='scss' scoped>
        .chart__wrapper {
            100%;
            height:100%;
            position:relative;
            padding:15px;
        }
    </style>
    日常所遇,随手而记。
  • 相关阅读:
    集群临时重启
    elasticsearch索引目录设置
    elasticsearch索引路径规则
    spring boot 使用application.properties 进行外部配置
    ELASTICSEARCH健康red的解决
    Elasticsearch——使用_cat查看Elasticsearch状态
    vmstat命令
    ava Maven项目之Nexus私服搭建和版本管理应用
    android 2.2 videoView 诡异bug
    华为部分设备运行很卡的问题
  • 原文地址:https://www.cnblogs.com/zhihou/p/8417574.html
Copyright © 2020-2023  润新知