写展示大屏踩到的坑总结与常用到的echarts图表配置收录

写系统展示大屏已经写了很多个了,但是还是踩坑不少,有些做过的图表经常用到,每次都要自己重新写配置参数,效率特别低,自我感觉非常难受,所以我决定总结一下。

所谓的系统展示大屏就是下图的这种,(签了保密协议了,所以打码是对公司的尊重)

 

 

坑1:这种因为要自适应,我一般都是用的弹性布局,这次我发现弹性布局有坑,虽然布局的时候按照比例了。但是元素多了还是会改变比例,

我找到了解决办法,就是在设置flex:1;这种比例的时候,一定要加上overflow:hidden。这样父元素就不会因为子元素超出父元素的原始高度而把元素撑大。

坑2:设置背景图的时候,background-size:100%;一定要加上

 

下面到了收录echarts配置的时刻啦

 

1、下图这种类型的饼图(代码用于vue项目)

代码如下

 this.errorbingChart = this.$echarts.init(this.$refs.errorAnalyzeEcharts);
                this.errorbingChart.setOption({
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    grid: {
                        top: '10%',
                        // left: '6%',
                        right: '0%',
                        bottom: '15%',
                        // containLabel: true
                    },
                    calculable : true,
                    color:['#0E6DE9', '#AC4ED3','#FFD74A','#00AF6D'],
                    series : [
                        {
                            name:'半径模式',
                            type:'pie',
                            radius : [20, 80],
                            center : ['50%', '50%'],
                            roseType : 'radius',
                            label: {
                                normal: {
                                    show: false
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            lableLine: {
                                normal: {
                                    show: false
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            data:[
                                {value:10, name:'OEE'},
                                {value:5, name:'故障'},
                                {value:15, name:'停机'},
                                {value:25, name:'其他'},
                            ]
                        }
                    ]
                })

2、环形饼图

代码如下

 this.analyzeEchart = this.$echarts.init(this.$refs.analyzeEcharts);
                this.analyzeEchart.setOption({
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b}: {c} ({d}%)"
                    },
                    color:['#0E6DE9', '#AC4ED3','#FFD74A','#00AF6D'],
                    series: [
                        {
                            name:'百分比',
                            type:'pie',
                            radius: ['50%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                normal: {
                                    show: false,
                                    position: 'center'
                                },
                                emphasis: {
                                    show: true,
                                    textStyle: {
                                        fontSize: '30',
                                        fontWeight: 'bold'
                                    }
                                }
                            },
                            labelLine: {
                                normal: {
                                    show: false
                                }
                            },
                            data:[
                                {value:335, name:'正常'},
                                {value:310, name:'风险'},
                                {value:234, name:'故障'},
                                {value:135, name:'预测'},
                            ]
                        }
                    ]
                })

3.柱状图

代码如下

 this.TimeUseEchart = this.$echarts.init(this.$refs.timeUseEcharts);
                this.TimeUseEchart.setOption({
                    grid: {
                        top: '0%',
                        // left: '6%',
                        right: '0%',
                        bottom: '15%',
                        // containLabel: true
                    },
                    color: ['#0E6DE9', '#AC4ED3', '#E6AF08','#00AF6D'],
                    tooltip : {
                        trigger: 'axis',
                        axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                            type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        top:'25%',
                        containLabel: true
                    },
                    xAxis : [
                        {
                            type : 'category',
                            data : ['6月15', '6月16', '6月17', '6月18', '6月19'],
                            axisTick: {
                                alignWithLabel: true
                            },
                            axisLine:{
                                lineStyle:{
                                    color:'#0090FF',
                                }
                            },
                            splitLine : {
                                show : false,
                                lineStyle:{
                                    color:'#0090FF',
                                }
                            }

                        }
                    ],
                    yAxis : [
                        {
                            type : 'value',
                            axisLine:{
                                lineStyle:{
                                    color:'#0090FF',
                                }
                            },
                            splitLine : {
                                show : false,
                                lineStyle:{
                                    color:'#0090FF',
                                }
                            }
                        }
                    ],
                    series : [
                        {
                            name:'负荷时间',
                            type:'bar',
                            barWidth: '10%',
                            data:[6.1, 6.3, 5.9, 6.0, 6.2]
                        },
                        {
                            name:'操作时间',
                            type:'bar',
                            barWidth: '10%',
                            data:[6.2, 6.2, 6.0, 5.9, 6.3]
                        },
                        {
                            name:'净操作时间',
                            type:'bar',
                            barWidth: '10%',
                            data:[6.0, 6.4, 5.8, 6.1, 6.1]
                        },
                        {
                            name:'有效操作时间',
                            type:'bar',
                            barWidth: '10%',
                            data:[6.0, 6.4, 5.8, 6.1, 6.1]
                        }
                    ]
                })

4、横向柱状图

代码如下

 this.deviceTypeEchart = this.$echarts.init(this.$refs.deviceTypeChart);
                this.deviceTypeEchart.setOption({
                    tooltip : {
                        trigger: 'axis',
                        axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                            type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                        }
                    },

                    grid: {
                        left: '3%',
                        right: '10%',
                        bottom: '3%',
                        top:'2%',
                        containLabel: true
                    },
                    color:['#00C4F5'],
                    xAxis:  {
                        type: 'value',
                        splitLine : {
                            show : false,
                            lineStyle:{
                                color:'#0090FF',
                            }
                        },
                        axisLine:{
                            lineStyle:{
                                color:'#0090FF',
                            }
                        },
                        axisLabel:{
                            formatter:'{value}%',
                            color:'#5AD381',
                            fontSize:'12px'
                        },
                    },
                    yAxis: {
                        type: 'category',
                        data: ['端末成型机','磁浮车运输专用车','升降车','空压站储气罐'],
                        axisLabel:{
                            interval: 0 ,
                            rotate:20,
                            color:'#5AD381',
                            fontSize:'12px'
                        },
                        splitLine : {
                            show : false,
                            lineStyle:{
                                color:'#0090FF',
                            }
                        },
                        axisLine:{
                            lineStyle:{
                                color:'#0090FF',
                            }
                        }
                    },
                    series: [
                        {
                            type: 'bar',
                            stack: '总量',
                            label: {
                                normal: {
                                    show: true,
                                    position: 'right'
                                }
                            },
                            barWidth: '30%',
                            data: [20, 30, 38, 38]
                        }
                    ]
                })

5、仪表盘(哈哈。我们的设计能把echarts的仪表盘改得面目全非,不过还挺好看)

代码如下:(需要传参)

 initStatusEcharts (target,data) {
                let peopleEchart = this.$echarts.init(document.getElementById(target));
                peopleEchart.setOption({
                    toolbox: { //可视化的工具箱
                        show: false,
                        feature: {
                            restore: { //重置
                                show: true
                            },
                            saveAsImage: {//保存图片
                                show: true
                            }
                        }
                    },
                    series: [{
                        name: '业务指标',
                        type: 'gauge',
                        // startAngle:200,
                        // endAngle:0,
                        radius:40,
                        axisLine: {
                            show:true,
                            // 属性lineStyle控制线条样式
                            lineStyle: {
                                width: 10,
                                color:[[0.7,'#01b4ff'],[1, '#262795']]
                            }
                        },
                        splitLine:{
                            show:false,
                        },
                        axisTick:{
                            show:false,
                        },
                        axisLabel:{
                            show:false,
                        },
                        pointer:{
                            length:'45px',
                            width:'4px',
                        },
                        detail: {
                            // offsetCenter:[0,'-120%'],
                            fontSize:14,
                            fontWeight:"bold",
                            formatter:'{value}%'
                        },
                        data: [
                            {value: data}
                        ]
                    }]
                });
                window.addEventListener('resize', () => {
                    peopleEchart.resize()
                })
            }

6、雷达图

 

代码如下

let peopleEchart = this.$echarts.init(this.$refs.targetEcharts);
                peopleEchart.setOption({

                    legend: {                        // 图例组件
                        // show: true,
                        icon: 'rect',                   // 图例项的 icon。ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'也可以通过 'image://url' 设置为图片,其中 url 为图片的链接,或者 dataURI。可以通过 'path://' 将图标设置为任意的矢量路径。
                        top : '40%',                    // 图例距离顶部边距
                        left : '15%',                   // 图例距离左侧边距
                        // itemWidth: 10,                  // 图例标记的图形宽度。[ default: 25 ]
                        // itemHeight: 10,                 // 图例标记的图形高度。[ default: 14 ]
                        // itemGap: 30,                	// 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔,纵向布局时为纵向间隔。
                        // orient: 'vertical',             // 图例列表的布局朝向,'horizontal'为横向,''为纵向.
                        // textStyle: {                    // 图例的公用文本样式。
                        //     fontSize: 15,
                        //     color: '#fff'
                        // },
                        data: [{                    // 图例的数据数组。数组项通常为一个字符串,每一项代表一个系列的 name(如果是饼图,也可以是饼图单个数据的 name)。图例组件会自动根据对应系列的图形标记(symbol)来绘制自己的颜色和标记,特殊字符串 ''(空字符串)或者 '\n'(换行字符串)用于图例的换行。
                            icon: 'rect',               // 图例项的 icon。
                            textStyle: {                // 图例项的文本样式。
                                color: 'rgba(51,0,255,1)',
                                fontWeight: 'bold'		// 文字字体的粗细,可选'normal','bold','bolder','lighter'
                            }
                        },{
                            icon: 'rect',
                            textStyle: {
                                color: 'rgba(255,0,0,1)',
                                fontWeight: 'bold'		// 文字字体的粗细,可选'normal','bold','bolder','lighter'
                            }
                        }],
                    },

                    radar: [{                       // 雷达图坐标系组件,只适用于雷达图。
                        center: ['50%', '50%'],             // 圆中心坐标,数组的第一项是横坐标,第二项是纵坐标。[ default: ['50%', '50%'] ]
                        radius: 50,                        // 圆的半径,数组的第一项是内半径,第二项是外半径。
                        startAngle: 90,                     // 坐标系起始角度,也就是第一个指示器轴的角度。[ default: 90 ]
                        name: {                             // (圆外的标签)雷达图每个指示器名称的配置项。
                            formatter: '{value}',
                            textStyle: {
                                fontSize: 12,
                                color: '#00CAFF'
                            }
                        },
                        nameGap: 15,                        // 指示器名称和指示器轴的距离。[ default: 15 ]
                        splitNumber: 4,                     // (这里是圆的环数)指示器轴的分割段数。[ default: 5 ]
                        shape: 'circle',                    // 雷达图绘制类型,支持 'polygon'(多边形) 和 'circle'(圆)。[ default: 'polygon' ]
                        axisLine: {                         // (圆内的几条直线)坐标轴轴线相关设置
                            lineStyle: {
                                color: '#fff',                   // 坐标轴线线的颜色。
                                width: 1,                      	 // 坐标轴线线宽。
                                type: 'solid',                   // 坐标轴线线的类型。
                            }
                        },
                        // splitLine: {                        // (这里是指所有圆环)坐标轴在 grid 区域中的分隔线。
                        //     lineStyle: {
                        //         color: '#fff',                       // 分隔线颜色
                        //         width: 2, 							 // 分隔线线宽
                        //     }
                        // },
                        // splitArea: {                        // 坐标轴在 grid 区域中的分隔区域,默认不显示。
                        //     show: true,
                        //     areaStyle: {                            // 分隔区域的样式设置。
                        //         color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)'],       // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
                        //     }
                        // },
                        indicator: [{               // 雷达图的指示器,用来指定雷达图中的多个变量(维度),跟data中 value 对应
                            name: '可用率',                           // 指示器名称
                           value: 100,                               // 指示器的最大值,可选,建议设置
                            //color: '#fff'                           // 标签特定的颜色。
                        }, {
                            name: '信息化',
                            value: 50
                        }, {
                            name: '利用率',
                            value: 80
                        }, {
                            name: '性能',
                            value: 56
                        }, {
                            name: '质量',
                            value: 65
                        },
                            {
                                name: '响应率',
                                value: 88
                            }
                        ]
                    }],
                    series: [{
                        name: '雷达图',             // 系列名称,用于tooltip的显示,legend 的图例筛选,在 setOption 更新数据和配置项时用于指定对应的系列。
                        type: 'radar',              // 系列类型: 雷达图
                        itemStyle: {                // 折线拐点标志的样式。
                            normal: {                   // 普通状态时的样式
                                lineStyle: {
                                    width: 1
                                },
                                opacity: 0.2
                            },
                            emphasis: {                 // 高亮时的样式
                                lineStyle: {
                                    width: 5
                                },
                                opacity: 1
                            }
                        },
                        data: [{                    // 雷达图的数据是多变量(维度)的
                            name: '图例二',                 // 数据项名称
                            value: [50, 60, 80, 55, 60,70],        // 其中的value项数组是具体的数据,每个值跟 radar.indicator 一一对应。
                            symbol: 'circle',                   // 单个数据标记的图形。
                            symbolSize: 5,                      // 单个数据标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10。
                            label: {                    // 单个拐点文本的样式设置
                                normal: {
                                    // show: true,             // 单个拐点文本的样式设置。[ default: false ]
                                    // position: 'top',        // 标签的位置。[ default: top ]
                                    distance: 5,            // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。[ default: 5 ]
                                    color: 'rgba(255,0,0,1)',          // 文字的颜色。如果设置为 'auto',则为视觉映射得到的颜色,如系列色。[ default: "#fff" ]
                                    fontSize: 14,           // 文字的字体大小
                                    formatter:function(params) {
                                        return params.value;
                                    }
                                }
                            },
                            itemStyle: {                // 单个拐点标志的样式设置。
                                normal: {
                                    borderColor: 'rgba(255,215,74,1)',       // 拐点的描边颜色。[ default: '#000' ]
                                    borderWidth: 3,                        // 拐点的描边宽度,默认不描边。[ default: 0 ]
                                }
                            },
                            lineStyle: {                // 单项线条样式。
                                normal: {
                                    opacity: 0.5            // 图形透明度
                                }
                            },
                            areaStyle: {                // 单项区域填充样式
                                normal: {
                                    color: 'rgba(255,215,74,0.6)'       // 填充的颜色。[ default: "#000" ]
                                }
                            }
                        }, {
                            name: '图例一',
                            value: [35, 60, 50, 20, 84,67],

                            symbol: 'circle',
                            symbolSize: 5,
                            label: {
                                normal: {
                                    // show: true,
                                    // position: 'top',
                                    distance: 5,
                                    color: 'rgba(51,0,255,1)',
                                    fontSize: 14,
                                    formatter:function(params) {
                                        return params.value;
                                    }
                                }
                            },
                            itemStyle: {
                                normal: {
                                    borderColor: 'rgba(14,249,179,1)',
                                    borderWidth: 3,
                                }
                            },
                            lineStyle: {
                                normal: {
                                    opacity: 0.5
                                }
                            },
                            areaStyle: {
                                normal: {
                                    color: 'rgba(14,249,179,0.5)'
                                }
                            }
                        }]
                    }, ]

                });

 

 

7、饼图

代码如下

  var tableStatusDiv = document.getElementById('tableStatus');
            var myChart1 = echarts.init(tableStatusDiv);
            var option = {
                title: {
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{b} : {c} ({d}%)"
                },
                legend: {
                    x: 'center',
                    y: '5%',
                    textStyle:{
                        color:'#fff'
                    }
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {show: true},
                        magicType: {
                            show: true,
                            type: ['pie', 'funnel']
                        }
                    }
                },
                color: ['#37A2DA', '#67E0E3', '#ffb819', '#e6ab95', '#E7BCF3', '#ACA5FF', '#32C5E9', '#9FE6B8', '#FF9F7F'],
                calculable: true,
                series: [
                    {
                        name: '表情况',
                        type: 'pie',
                        radius: ['20%', '65%'],
                        center: ['50%', '50%'],
                        roseType: 'area',
                        data: datas,
                        label: {
                            normal: {
                            }
                        }
                    }
                ]
            };

 

窗口改变自适应窗口事件

  window.addEventListener('resize', () => {
                this.deviceTypeEchart.resize()
                this.toolingTypeEchart.resize()
                this.analyzeEchart.resize()
                this.targetEchart.resize()
                // this.TimeUseEchart.resize()
            })

 

 

暂时总结这么多,以后补充

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值