美文网首页php学习
怎么给Echart图加背景图片

怎么给Echart图加背景图片

作者: 简书超级会员 | 来源:发表于2017-09-05 13:48 被阅读492次

Echart3图越来越强大,最近公司有这样的需求,客户对界面要求比较高,专门设计了几种图,查阅了官网的使用API。算是实现了吧!

背景有方格子的图
    option = {
        title: {
            text: "设备总体健康报表",
            textStyle: {
                color: "#ffffff",
                fontWeight: 'bold'
            },
            left: "10",
            top: '10'
        },
        tooltip: {
            trigger: 'axis'
        },
        color: ['#e8b609', '#e74e54', '#79e4e4', '#29b4ec'],
        grid: {
            left: '3%',
            right: '4%',
            bottom: '20%',
            containLabel: true,
        },
        legend: {
            right: '30',
            top: '10',
            orient: 'horizontal',
            textStyle: {
                color: '#ffffff'
            },
            icon: 'roundRect',
            data: ['宝山', '东山', '青山', '梅山']
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            nameTextStyle: {
                fontSize: '16'
            },
            axisLabel: {
                height: '50',
                textStyle: {
                    color: '#ffffff',
                    fontSize: '16'
                }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    type: 'solid'
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#ffffff'
                }
            },
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '、十二月']
        },
        yAxis: {
            type: 'value',
            axisLine: true,
            axisLabel: {
                formatter: '{value} %',
                textStyle: {
                    color: '#ffffff'
                }
            }
        },
        series: [
            {
                name: '宝山',
                type: 'line',
                symbolSize: 10,
                data: [30, 33, 34, 33, 42, 35, 34]
            },
            {
                name: '东山',
                type: 'line',
                symbolSize: 15,
                data: [5, 2, 2, 5, 3, 2, 3],
            },
            {
                name: '青山',
                type: 'line',
                symbolSize: 15,
                data: [20, 30, 15, 15, 22, 23, 34],
            },
            {
                name: '梅山',
                type: 'line',
                symbolSize: 15,
                data: [33, 30, 42, 35, 43, 23, 32],
            }

        ],
        graphic: [
            {
                type: 'image',
                id: 'logo',
                right: '11',
                bottom: '28%',
                z: 1000,
                bounding: 'raw',
                style: {
                    image: 'image/shadow.png',
                    width: 945
                }
            }
        ],
    };
有一个背景图的渐变色饼图
     option = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        color: ['#e8b609', '#e74e54', '#29b4ec'],
        grid: {
            top: 'top'
        },
        legend: {
            left: 'center',
            top: '30',
            orient: 'vertical',
            textStyle: {
                color: '#ffffff',
                fontSize: '20',
                verticalAlign: 'bottom'
            },
            itemHeight: '50',
            icon: 'rect',
            data: ['335', '310', '234'],
            formatter: function (name) {
                return "指标名称\n" + name;
            }
        },
        graphic: [
            {
                type: 'image',
                left: '32',
                top: 8,
                z: -10,
                bounding: 'raw',
                style: {
                    image: 'image/circle_equipment.png',
                    width: 200,
//                    height: 150,
//                    opacity: 0.4
                }
            }


        ],
        series: [
            {
                name: '访问来源',
                type: 'pie',
                radius: ['30%', '60%'],
                center: ['22%', '36%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [
                    {
                        value: 335,
                        name: '335',
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: '#fcd661'
                                }, {
                                    offset: 1,
                                    color: '#fca81f'
                                }])
                            }
                        }

                    },
                    {
                        value: 310,
                        name: '310',
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: '#48e4c1'
                                }, {
                                    offset: 1,
                                    color: '#15aa97'
                                }])
                            }
                        }
                    },
                    {
                        value: 234,
                        name: '234',
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: '#2cc1ff'
                                }, {
                                    offset: 1,
                                    color: '#148ccb'
                                }])
                            }
                        }
                    }
                ]
            }
        ]
    };
默认展示数据的饼图
    option = {
        title: {
            text: "东山",
            textStyle: {
                color: "#ffffff",
            },
            left: "center",
            bottom: "75"
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        color: ['#e8b609', '#e74e54', '#29b4ec'],
        grid: {
            top: 'top'
        },
        legend: {
            left: 'center',
            bottom: '26',
            orient: 'horizontal',
            textStyle: {
                color: '#ffffff'
            },
            icon: 'circle',
            data: ['335', '310', '234'],



        },
        graphic: [
            {
                type: 'image',
                id: 'logo',
                right: 11,
                top: 8,
                z: -10,
                bounding: 'raw',
                style: {
                    image: 'image/circlebg.png',
                    width: 200,
//                    height: 150,
//                    opacity: 0.4
                }
            }


        ],
        series: [
            {
                name: '访问来源',
                type: 'pie',
                radius: ['50%', '70%'],
                center: ['50%', '36%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: function (params) {
//                            if (params.name == "335") {
//                            }
//                            return "";
//                        return params.value + '\n' + params.name;
                        },
                    },

                    emphasis: {
                        show: false,
                        textStyle: {
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    }

                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [
                    {value: 335, name: '335'},
                    {value: 310, name: '310'},
                    {value: 234, name: '234'}
                ]
            }, {
                name: '完成处理',
                type: 'pie',
                clockWise: false,
                hoverAnimation: true,
                radius: ['50', '50'],
                center: ['50%', '36%'],
                label: {
                    normal: {
                        position: 'center'
                    }
                },
                tooltip: {
                    show: false
                },
                data: [
                    {
                        label: {
                            normal: {
                                formatter: '879',
                                textStyle: {
                                    color: '#000000',
                                    fontSize: 46,
                                    fontWeight: 'bold'
                                }
                            }
                        }
                    }
                ]
            }
        ]
    };

相关文章

  • 怎么给Echart图加背景图片

    Echart3图越来越强大,最近公司有这样的需求,客户对界面要求比较高,专门设计了几种图,查阅了官网的使用API。...

  • echart饼图设置背景图片

    1,运用echart属性设置图片 XXX.js 2.用一个大的div包裹图表容器main,在大的div上定位一张i...

  • echart地图使用经验-地图变形和添加数据

    关于echart2,echart3地图的使用一点人生经验: 1.echart3,echa...

  • echart使用心得

    最近在弄商城的图表数据,要用到了echart.js,echart是支持多种图表的,有折线图,饼图,柱形图等等,我们...

  • 10 CSS的背景

    通过CSS背景属性,可以给页面元素添加背景样式。背景属性可以设置背景颜色、背景图片、背景平铺、背景图片位置、背景图...

  • UIImage工具类

    平时在写一些demo的过程中,想给按钮加一些背景图片,又苦于没有美工去做切图,而只设置按钮背景颜色的话又没有高亮效...

  • YII2 echart 饼图 demo

    echart 使用 视图层view.php 此次针对 echart 饼状图。控制器代码类似。 主要记录一下数据格式...

  • 给背景图片加颜色遮罩

    原理: 利用定位,将透明颜色加到图片上 html css

  • vue框架下实现甘特图(dhtmlxGantt)

    项目中要用到甘特图,最开始研究了echart,实现的样式如下: 对比下面的原型图,发觉相差甚大且通过echart不...

  • echart迁徙图

    需要的js有 0.jquery 1.echart.js 2,china.js 代码奉上 html页面

网友评论

    本文标题:怎么给Echart图加背景图片

    本文链接:https://www.haomeiwen.com/subject/irpujxtx.html