echars设置属性参考

图表标题

title: {
        x: 'left',                 // 水平安放位置,默认为左对齐,可选为:
                                   // 'center' ¦ 'left' ¦ 'right'
                                   // ¦ {number}(x坐标,单位px)
        y: 'top',                  // 垂直安放位置,默认为全图顶端,可选为:
                                   // 'top' ¦ 'bottom' ¦ 'center'
                                   // ¦ {number}(y坐标,单位px)
        //textAlign: null          // 水平对齐方式,默认根据x设置自动调整
        backgroundColor: 'rgba(0,0,0,0)',
        borderColor: '#ccc',       // 标题边框颜色
        borderWidth: 0,            // 标题边框线宽,单位px,默认为0(无边框)
        padding: 5,                // 标题内边距,单位px,默认各方向内边距为5,
                                   // 接受数组分别设定上右下左边距,同css
        itemGap: 10,               // 主副标题纵向间隔,单位px,默认为10,
        textStyle: {
            fontSize: 18,
            fontWeight: 'bolder',
            color: '#333'          // 主标题文字颜色
        },
        subtextStyle: {
            color: '#aaa'          // 副标题文字颜色
        }
    },

提示框

tooltip: {
        trigger: 'item',           // 触发类型,默认数据触发,见下图,可选为:'item' ¦ 'axis'
        showDelay: 20,             // 显示延迟,添加显示延迟可以避免频繁切换,单位ms
        hideDelay: 100,            // 隐藏延迟,单位ms
        transitionDuration : 0.4,  // 动画变换时间,单位s
        backgroundColor: 'rgba(0,0,0,0.7)',     // 提示背景颜色,默认为透明度为0.7的黑色
        borderColor: '#333',       // 提示边框颜色
        borderRadius: 4,           // 提示边框圆角,单位px,默认为4
        borderWidth: 0,            // 提示边框线宽,单位px,默认为0(无边框)
        padding: 5,                // 提示内边距,单位px,默认各方向内边距为5,
                                   // 接受数组分别设定上右下左边距,同css
        axisPointer : {            // 坐标轴指示器,坐标轴触发有效
            type : 'line',         // 默认为直线,可选为:'line' | 'shadow'
            lineStyle : {          // 直线指示器样式设置
                color: '#48b',
                width: 2,
                type: 'solid'
            },
            shadowStyle : {                       // 阴影指示器样式设置
                width: 'auto',                   // 阴影大小
                color: 'rgba(150,150,150,0.3)'  // 阴影颜色
            }
        },
        textStyle: {//文本设置
            color: '#fff'
        }
        position: function (p) {// 设置鼠标移入后文本的位置
           return [p[0]-50, p[1] - 150];
        },
        formatter:function(params){//提示文本样式拼接
    		// console.log(params)
    		params = params.map(function(val,i){
    		//取不到颜色,用于拼接颜色
        	val.marker = '<span style="display:inline-block;margin-right:5px;border-			radius:10px;width:10px;height:10px;background-color:'+_color[i]+';"></span>';
        	return val;
    		})
    		var t = '';
    		t += params[0].axisValueLabel + '</br>'
    		params.forEach(function(val){//拼接要显示的文本
        	t += val.marker + val.seriesName + ':' + val.value +'</br>'
    		})
   		 	return t;
		}
    },

图例

legend: {
        orient: 'horizontal',      // 布局方式,默认为水平布局,可选为:
                                   // 'horizontal' ¦ 'vertical'
        x: 'center',               // 水平安放位置,默认为全图居中,可选为:
                                   // 'center' ¦ 'left' ¦ 'right'
                                   // ¦ {number}(x坐标,单位px)
        y: 'top',                  // 垂直安放位置,默认为全图顶端,可选为:
                                   // 'top' ¦ 'bottom' ¦ 'center'
                                   // ¦ {number}(y坐标,单位px)
        backgroundColor: 'rgba(0,0,0,0)',
        borderColor: '#ccc',       // 图例边框颜色
        borderWidth: 0,            // 图例边框线宽,单位px,默认为0(无边框)
        padding: 5,                // 图例内边距,单位px,默认各方向内边距为5,
                                   // 接受数组分别设定上右下左边距,同css
        itemGap: 10,               // 各个item之间的间隔,单位px,默认为10,
                                   // 横向布局时为水平间隔,纵向布局时为纵向间隔
        itemWidth: 20,             // 图例图形宽度
        itemHeight: 14,            // 图例图形高度
        top:5,					   // 图例距离上边框位置
        left:5, 				   // 图例距离左边框位置
        textStyle: {
            color: '#333',         // 图例文字颜色
            fontSize:14			   // 图例文字大小
        }
    },

x轴

xAxis : {
                type : 'category', // type:坐标轴类型。可选
                        //1.'value' 数值轴 2.'category' 类目轴,3.'time' 时间轴, 4.'log' 对数轴。
                data : ['上海','北京'], //x轴下面的数据
                axisTick: {
                    show: false,  //是否显示网状线 默认为true
                    alignWithLabel: true
                },
                axisLabel:{    //用于设置x下面的字体
                    show:true,  //这里的show用于设置是否显示x轴下的字体 默认为true
                    interval:0, //可以设置成 0 强制显示所有标签。如果设置为 1,表示『隔一个标签显示一个标签』,
                                //如果值为 2,表示隔两个标签显示一个标签,以此类推。
                    textStyle:{   //textStyle里面写x轴下的字体的样式
                        color:'#333',
                        fontSize:13
                    }
                },
                axisLine:{
                    show:true,  //这里的show用于设置是否显示x轴那一条线 默认为true
                    lineStyle:{ //lineStyle里面写x轴那一条线的样式
                        color:'#6FC6F3',
                         width:2,    //轴线的粗细 我写的是2 最小为0,值为0的时候线隐藏
                    }
                }
            },

y轴设置

yAxis:[
    {
        min:0, //y轴的最小值
        max:100, //y轴最大值 
        interval:20, //值之间的间隔
        scale:true, //为true后,坐标刻度不会从0开始。注意仅在type:'value'时有效
        type:'value',// type坐标轴类型:[ default: 'value' ]
        splitLine:{show:false}, //去除网状线 默认为true
            axisLabel:{//用于设置y轴的字体
                show:true,  //这里的show用于设置是否显示y轴下的字体 默认为true
                textStyle:{   //textStyle里面写y轴下的字体的样式
                    color:'#333',
                    fontSize:13
                }
            },
        axisLine:{//用于设置y轴的那一条线
            show:true,  //这里的show用于设置是否显示y轴那一条线 默认为true
            lineStyle:{ //lineStyle里面写y轴那一条线的样式
                color:'#6FC6F3',
                width:2,    //轴线的粗细 我写的是2 最小为0,值为0的时候线隐藏
            }
        }
        nameLocation:'end',//下面三个是设置双y轴
        scale:true,		//坐标轴起点不从0开始
        position: 'left',//左边y轴
    },
    {
        position: 'right',//其他差不多
    }
]
*注意:设置双y轴的时候值域series中要添加:yAxisIndex: 0,或yAxisIndex: 1,*

网格

grid: {
        x: 80,
        y: 60,
        x2: 80,
        y2: 60,
        // width: {totalWidth} - x - x2,
        // height: {totalHeight} - y - y2,
        backgroundColor: 'rgba(0,0,0,0)',
        borderWidth: 1,
        borderColor: '#ccc'
    },
    或
grid: {
        top: '0%',
		right: '0%',
		bottom: '0%',
		left: '0%',
		containLabel:true
    },

折叠型例子

var xData = [];//近五年

var myDate = new Date();
for(var i=4;i>=0;i--){
    var tyear = myDate.getFullYear();
    xData.push(tyear-i + '');
}
var data = {
        area: _this.data.xData,
        legend: ['有人户分离', '无人户分离'],
        data: [
            [34243, 26503, 22335, 23444, 27038,21712,22355,23084,25240,27435],
            [5867, 3957, 6189, 4290, 3579,10157,8063,5975,13694,17714],
        ],
        sum:[40110,30460,28524,27734,30617,31869,30418,29060,38934,45149]
}
var colors = [
    ['#09833A', '#7BF311'],
    ['#F36229', '#F9A24C'],
    // ['#F9A14B', '#F36128'],
    // ['#7AF310', '#088339'],
];
var _color = ['#F36128','#088339','#FFFF00'];
var _options = {
    
    tooltip:{
        show:true,
        trigger: "axis",
        
        axisPointer: {
            type: "shadow",
            textStyle: {
                color: "#fff"
            }
        },
        textStyle:{
            fontSize: 12 * Global.common.screen_level,
        },
        position: function (p) {
            // 位置回调
            return [p[0]-50*Global.common.screen_level, p[1] - 150*Global.common.screen_level];
        },
        formatter:function(params){
            // console.log(params)
            params = params.map(function(val,i){
                val.marker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+_color[i]+';"></span>';
                return val;
            })
            var t = '';
            t += params[0].axisValueLabel + '</br>'
            params.forEach(function(val){
                t += val.marker + val.seriesName + ':' + val.value +'</br>'
            })
            return t;
        }
        
    },
    legend: {
        top: 10 * Global.common.screen_level,
        itemGap: 40 * Global.common.screen_level,
        textStyle: {
            fontSize: 14 * Global.common.screen_level,
            color: '#FFF'
        },
        data: data.legend
    },
    grid: {
        top:'20%',
        left: '0%',
        right: '0%',
        bottom: '10%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLabel: {
            color: '#FFF',
            fontSize: 14 * Global.common.screen_level,
        },
        axisLine: {
            lineStyle: {
                color: '#FFF'
            },
        },
        axisTick: {
            show: false,
        },
        nameTextStyle: {
            color: '#fff',
            fontSize: 14 * Global.common.screen_level
        },
        data:data.area
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            color: '#FFF',
            fontSize: 14 * Global.common.screen_level,
        },
        axisLine: {
            lineStyle: {
                color: '#FFF'
            }
        },
        axisTick: {
            show: false,
        },
        splitLine: {
            show:false
        },
    },
    series: [
        {
            name:'总数',
            data: data.sum,
            type: 'bar',
            barGap: "-100%",
            barWidth: '60%',
            label: {
                show: true,
                // position: [-55* Global.common.screen_level, -15 * Global.common.screen_level],
                position: 'top',
                textStyle: {
                    color: '#FFFF00',
                    fontSize:14 * Global.common.screen_level,
                }
            },
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            },
        }
    ]
};
for (var i = 0; i < data.legend.length; i++) {
    _options.series.unshift({
        name: data.legend[i],
        type: 'bar',
        stack: '总量',
        barWidth: '60%',
        label: {
            show: true,
            position: 'inside',
            color:'#FFF',
            fontSize:14 * Global.common.screen_level,
        },
        itemStyle: {
            normal: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0,
                        color: colors[i][1] // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: colors[i][0] // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            }
        },
        data: data.data[i]
    })
}

样品
在这里插入图片描述
双y轴示例

var data1= [{name:2012,value:141000},{name:2013,value:137000},{name:2014,value:139000},{name:2015,value:190000},{name:2016,value:240000},{name:2017,value:200000},{name:2018,value:238000},{name:2019,value:232000},{name:2020,value:258000}]          
var data2= [{name:2012,value:25600},{name:2013,value:21000},{name:2014,value:25000},{name:2015,value:30000},{name:2016,value:35000},{name:2017,value:36000},{name:2018,value:35000},{name:2019,value:31000},{name:2020,value:36000}]          
var _options = {
    tooltip: {
        trigger: 'axis',
        textStyle:{
            fontSize:16
        },
        position: function (p) {
            // 位置回调
            return [p[0]-40, p[1] - 120];
        }
    },
    legend: {
        data: ['来沪人员','境外人员'],
        textStyle: {
            fontSize: 14 ,
            color: '#fff'
        },
        itemGap: 40 ,
        top: 10 
    },
    grid: {
        top: '30%',
        right: '0%',
        bottom: '0%',
        left: '0%',
        containLabel:true
    },
    xAxis:  {
        type: 'category',
        boundaryGap: false,
        data: [2012,2013,2014,2015,2016,2017,2018,2019,2020],
        // name: '(月)',
        nameTextStyle: {
            color: '#fff',
            fontSize: 14 
        },
        axisLabel: {
            color: '#fff',
            fontSize: 14 
        },
        axisLine: {
            lineStyle: {
                color: '#fff'
            }
        },
    },
    yAxis:[
        
        {
            type: 'value',
            name:'来沪人员',
            nameLocation:'end',
            scale:true,
            position: 'left',
            nameTextStyle: {
                color: '#28F9D0',
                fontSize: 14
            },
            axisLabel: {
                color: '#27F9CF',
                fontSize: 14 
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            splitLine: {
                show:false
            },
        },{
            type: 'value',
            name:'境外人员',
            scale:true,
            position: 'right',
            nameTextStyle: {
                color: '#FFE81F',
                fontSize: 14 
            },
            axisLabel: {
                color: 'yellow',
                fontSize: 14
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            splitLine: {
                show:false
            },
        }
    ],
    
    series: [
        {
            name: '来沪人员',
            type:'line',
            data: data1,
            smooth:true,
            yAxisIndex: 0,
            itemStyle: {
                color: '#1AFFE7'
            },
            areaStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 1,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                        offset: 0, color: 'rgba(0, 228, 255, 0)' // 0% 处的颜色
                    },
                    {
                        offset: 1, color: 'rgba(0, 228, 255, 0.8)' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            },
            symbolSize: 3 ,
            symbol: 'circle'
        },
        {
            name: '境外人员',
            type:'line',
            data: data2,
            smooth:true,
            yAxisIndex: 1,
            itemStyle: {
                color: '#FFC21A'
            },
            areaStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 1,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                        offset: 0, color: 'rgba(255, 217, 7, 0)' // 0% 处的颜色
                    },{
                        offset: 1, color: 'rgba(255, 217, 7, 0.8)' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            },
            symbolSize: 3,
            symbol: 'circle'
        }
    ]
};

示例图
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值