博客
关于我
ECharts——双向柱状图
阅读量:358 次
发布时间:2019-03-04

本文共 6070 字,大约阅读时间需要 20 分钟。

<!DOCTYPE html><html><head> @include('./header.html', { "title": "首页" }) </head><body>    <div class="wrap">        <div id="echart_test2"></div>        <div id="echart_test"></div>    </div>    <script src="dist/js/lib/jquery/jquery-3.3.1.min.js"></script>    <script src="dist/js/lib/echarts/echarts-4.2.1.min.js"></script>    <style>        #echart_test {                display: inline-block;            width: 400px;            height: 400px;        }                #echart_test2 {                display: inline-block;            width: 400px;            height: 400px;        }    </style></body><script>    var sechart2 = echarts.init(document.getElementById('echart_test'));    // var salvProName = ["安徽省", "河南省", "浙江省", "湖北省", "贵州省", "江西省", "江苏省", "四川省", "云南省", "湖南省"];    var salvProValue = [55, 67, 72, 74, 117, 135, 144, 154, 181, 239];    var salvProMax = []; //背景按最大值    for (let i = 0; i < salvProValue.length; i++) {            salvProMax.push(salvProValue[0])    }    option = {            backgroundColor: "white", //设置背景颜色        grid: {                left: '0%', //设置左边距            right: '0%',            bottom: '5%', //设置条状间距            top: '2%', //设置顶部间距            containLabel: true        },        tooltip: {                // trigger: 'axis',  //条状图阴影是否显示            // show: true,            axisPointer: {                    // type: 'shadow' //添加条状阴影            },            formatter: function(params) {                    return params[0].name +                    ' : ' + params[0].value            }        },        xAxis: {                show: false, //Y轴            type: 'value'        },        yAxis: [{                type: 'category',            inverse: true, // 显示顺序            axisLabel: {                    show: true,                textStyle: {                        color: 'black' //左侧字体颜色                },            },            splitLine: {                    show: false            },            axisTick: {                    show: false            },            axisLine: {                    show: false            },            // data: salvProName    //左侧文字显示        }, {                type: 'category',            inverse: true, //控制数字显示方向            axisTick: 'none',            axisLine: 'none',            show: true, //控制数字显示            axisLabel: {                    textStyle: {                        color: 'black',                    fontSize: '12'                },            },            data: salvProValue //数字显示        }],        series: [{                name: '值',            type: 'bar',            zlevel: 1,            itemStyle: {                    normal: {                        barBorderRadius: 30,                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{                            offset: 0,                        color: ' #2da5f1'                    }, {                            offset: 1,                        color: ' #58b7f4 '                    }]),                },            },            barWidth: 15, //条状图显示宽度              data: salvProValue        }, {                name: '背景',            type: 'bar',            barWidth: 15, //条状图占比宽度            barGap: '-100%', //top边距            barCategoryGap: '10%',            data: salvProMax,            itemStyle: {                    normal: {                        color: 'white',                    barBorderRadius: 30,                }            },        }, ]    };    sechart2.setOption(option)</script><script>    var sechart8 = echarts.init(document.getElementById('echart_test2'));    var yData = ['铜川市', '汉中市', '西安市', '商洛市', '延安市', '榆林市', '宝鸡市', '渭南市', '咸阳市', '安康市'];    var dataArr = [239, 181, 154, 144, 135, 117, 74, 72, 67, 55];    // var allDataArr = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000];    var option = {            backgroundColor: '#fff',        tooltip: {                show: false,            trigger: 'axis',            padding: [5, 5],            axisPointer: {                    type: 'shadow'            },            formatter: function(param) {                    return param[0].name + ":" + param[0].value            }        },        grid: {                left: '0%', //设置左边距            right: '0%',            bottom: '10%', //设置条状间距            top: '2%', //设置顶部间距            containLabel: true        },        xAxis: {                type: 'value',            axisLabel: {                    show: false            },            axisTick: {                    show: false            },            axisLine: {                    show: false            },            splitLine: {                    show: false            },            inverse: true        },        yAxis: [{                type: 'category',            data: dataArr,            // inverse: true,            axisLabel: {                    color: "#000",                fontSize: 12            },            axisTick: {                    show: false            },            axisLine: {                    show: false            }        }, {                type: 'category',            axisTick: 'none',            axisLine: 'none',            show: true,            axisLabel: {                    textStyle: {                        color: '#333',                    fontSize: 12                }            },            // data: dataArr        }],        series: [{                name: '',            type: 'bar',            data: dataArr,            barCategoryGap: '10%',            barWidth: 15,            zlevel: 1,            itemStyle: {                    normal: {                        barBorderRadius: 30,                    color: '#ebac4b'                }            }        }, {                name: '',            type: 'bar',            barWidth: 15,            barGap: '-100%',            barCategoryGap: '10%',            // data: allDataArr,            itemStyle: {                    normal: {                        color: '#fff'                }            }        }]    };    sechart8.setOption(option)</script></html>
  1. 样式图
    在这里插入图片描述

转载地址:http://syfg.baihongyu.com/

你可能感兴趣的文章
【Python】(十二)IO 文件处理
查看>>
【Oozie】(三)Oozie 使用实战教学,带你快速上手!
查看>>
师兄面试遇到这条 SQL 数据分析题,差点含泪而归!
查看>>
Java8新特性——并行流与顺序流
查看>>
如何通过 Dataphin 构建数据中台新增100万用户?
查看>>
C语言的数值溢出问题(上)
查看>>
BottomNavigationView控件item多于3个时文字不显示
查看>>
函数指针的典型应用-计算函数的定积分(矩形法思想)
查看>>
8051单片机(STC89C52)八个LED灯闪烁
查看>>
8051单片机(STC89C52)以定时器中断模式实现两倒计时器异步计时
查看>>
8051单片机(STC89C52)实现可修改初值(并可命令启停)的单倒计时器(Version1.1)
查看>>
用 wxPython 打印你的 App
查看>>
vue项目通过vue.config.js配置文件进行proxy反向代理跨域
查看>>
Linux下安装MySql过程
查看>>
原生vue实现VantUI中IndexBar索引导航栏功能
查看>>
android:使用audiotrack 类播放wav文件
查看>>
vue通过better-scroll 封装自定义的下拉刷新组件
查看>>
android解决:使用多线程和Handler同步更新UI
查看>>
vue自定义封装Loading组件
查看>>
解决移动端项目中苹果ios和安卓android手机点击输入框网页页面自动放大缩小
查看>>