zoukankan      html  css  js  c++  java
  • echarts实践-图表划分区域并设置不同颜色

    上一篇echarts实践-用线分割的点图介绍了echarts的基本操作及用标线分割点图的不同区域,如下为给图表划分区域。

    1、series节点下添加属性markArea增加区域

    (1)markArea节点下的data由多组区域数据构成,每组长度固定为2的对象分别用来固定左右及上下区间

    data: [
                    [{
                    yAxis: '2.5',//y轴坐标控制
                    itemStyle:{
                        color:'#c60c30'
                    }
                }, {
                    yAxis: '3.5'
                }]
                ,
                [{
                    yAxis: '4.5',
                    itemStyle:{
                        color:'#ffb400'
                    }
                }, {
                    yAxis: '6.5'
                }]
    

    (2)可全局控制区域的样式及单独控制每个区域的样式

    全局,在data的同一级添加如下代码:

    itemStyle: { //全局的
                    normal: { color: '#ff3333' }
                }
    

      

    单独控制:

     [{
                    yAxis: '2.5',//y轴坐标控制
                    itemStyle:{ //控制当前区域样式
                        color:'#c60c30'
                    }
                }, {
                    yAxis: '3.5'
                }]
    

    2、示例代码

    option = {
        title: {
            text: '标题',
            x: 'center'
        },
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            data : ['8/14','8/15','8/16','8/17','8/18','8/19','8/20']
        },
        yAxis: {
            axisLine:{show:false},
            name:'y轴标题',
            position: 'left',//y轴位置
            nameLocation: 'middle', //坐标轴名称显示位置
            type: 'value',
            max:20,//最大值
            nameGap:30//与y轴间距
        },
        series: [{
            itemStyle:{
                normal:{
                    color:'#666666'
                }
            },
            symbolSize: 15,//点的大小
            data: [
                [x='8/14', y=3.04],
                [x='8/14', y=9.04],
                ['8/15', 6.95],
                ['8/15', 7.58],
                ['8/15', 8.81],
                ['8/15', 8.33],
                ['8/16', 9.96],
                ['8/17', 7.24],
                ['8/18', 4.26],
                ['8/18', 10.84],
                ['8/20', 4.82],
                ['8/20', 5.68]
            ],
            type: 'scatter',
            markArea: { //标记区域
                itemStyle: { //全局的
                    normal: { color: '#ff3333' }
                },
                data: [
                    [{
                    yAxis: '2.5',//y轴坐标控制
                    itemStyle:{
                        color:'#c60c30'
                    }
                }, {
                    yAxis: '3.5'
                }]
                ,
                [{
                    yAxis: '4.5',
                    itemStyle:{
                        color:'#ffb400'
                    }
                }, {
                    yAxis: '6.5'
                }]
                ]
            },
            markLine: {//标线
                    symbol: ['none', 'none'],//去掉箭头
                    itemStyle: {
                        normal: {
                            lineStyle: { //全局的样式
                                type: 'solid',
                                 2
                            }
                            ,label: { show: false, position:'left' } }
                    },
                    data: [{
                            yAxis: 2.5,
                            itemStyle: {
                                normal: { color: '#c60c30' }
                            }
                    },
                    {
                            yAxis: 3.5,
                            itemStyle: {
                                normal: { color: '#c60c30' }
                            }
                    }
                    ,
                    {
                            yAxis: 4.5,
                            itemStyle: {
                                normal: { color: '#ffb400' }
                            }
                    },
                    {
                            yAxis: 6.5,
                            itemStyle: {
                                normal: { color: '#ffb400' }
                            }
                    }]
            }
        }
        
    ]
    };
    

      

    3、效果图

  • 相关阅读:
    [转]org.apache.poi3.1.7 Excle并发批量导入导出,格式设置方式需要修改
    [转]POI使用HSSF,XSSF,SXSSF三种方式
    [转]idea maven项目dependencies红线 解决办法
    mysqlGTID主从同步出现1236错误问题
    MySQL日志:slow query log
    telnet 去掉用户名和密码
    [PHP] 装饰器模式-结构型设计模式
    [GO] 变参函数-GO中函数传递变长参数
    [PHP] 数据映射器模式-结构型设计模式
    [GO-FLY] GO-FLY客服实现浏览器消息提示音
  • 原文地址:https://www.cnblogs.com/hepc/p/9550047.html
Copyright © 2011-2022 走看看