继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【前端统计图】echarts实现属性修改

拉莫斯之舞
关注TA
已关注
手记 306
粉丝 24
获赞 108

原图:


https://img2.mukewang.com/5d58e6ee0001964908470349.png

图片.png

原代码:

<!DOCTYPE html><html>

    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>

    <body>
        <!--   柱状统计图 -->
        <div class="row">
            <div id="main" style="width: 900px; height: 350px;  margin-top:80px;"></div>
        </div>
    </body>
    <script src="../../js/echarts/echarts.min.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));        // 指定图表的配置项和数据
        myChart.setOption({            title: {                text: '平均耗时(分钟)',

            },            tooltip: {                trigger: 'axis',                axisPointer: {                    type: 'shadow'
                }
            },            legend: {                /*  data: [ '2012年']*/
            },            grid: {                left: '3%',                right: '4%',                bottom: '3%',                containLabel: true
            },            xAxis: {                type: 'value',                boundaryGap: [0, 0.01]
            },            yAxis: {                type: 'category',                data: ['SA服务', '洗车', '总检', '喷漆', '钣金', '机修', '等号']
            },            series: [{                    name: '2012年',                    type: 'bar',                    itemStyle: {                        normal: {                            color: '#a8bcd4'
                        }
                    },                    data: [10, 20, 31, 14, 11, 67]
                }
            ]
        });    </script></html>

1:标题颜色属性修改

将图标主标题颜色修改成红色,只需要在 title:里面添加 textStyle: {color: 'red' }即可


https://img2.mukewang.com/5d58e6f10001a5f809060361.png

图片.png

 title: {                text: '平均耗时(分钟)',
             textStyle: {
                color: 'red'
            },
            },

2:x和y轴坐标颜色修改

https://img1.mukewang.com/5d58e6f400013c2908350359.png

图片.png


x轴坐标:

 xAxis: {                type: 'value',
                boundaryGap: [0, 0.01],
                axisLine:{  
            lineStyle:{  
                color:'#e33b38',  
                width:1,//这里是为了突出显示加上的  
            }  
        } 
            },

y轴坐标:

 yAxis: {                type: 'category',
                data: ['SA服务', '洗车', '总检', '喷漆', '钣金', '机修', '等号'],
                splitLine: {  
                lineStyle: {  
                    // 使用深浅的间隔色  
                    color: ['#e33b38']  
                }  
            },  
            nameTextStyle: {  
                color: ['#e33b38']  
                },  
            axisLine:{  
                lineStyle:{  
                    color:'#e33b38',  
                    width:1,//这里是为了突出显示加上的  
                }  
            }
            },

3:柱状图实现不同颜色

https://img.mukewang.com/5d58e6f80001a0be08310363.png

图片.png

    itemStyle: {                normal: {                color: function(params) {                
                var colorList = [                '#569afb','#ff6347','#561afb','#ff2347','#269afb','#fq6347'
                ];                return colorList[params.dataIndex]
                },                
                label: {                show: false
                }
                }
                },

4:柱状图粗细属性控制

  barWidth : 20,

https://img4.mukewang.com/5d58e6fc00012f7f08710372.png

图片.png


https://img2.mukewang.com/5d58e7180001be6405150311.png

图片.png

5:echarts处理图形与title之间的距离
参考链接
http://echarts.baidu.com/option.html#title



作者:祈澈菇凉
链接:https://www.jianshu.com/p/539a0cd5a506


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP