美文网首页
echarts 柱状图/折线图相关属性设置

echarts 柱状图/折线图相关属性设置

作者: lucky婧 | 来源:发表于2020-11-24 17:08 被阅读0次
      let myChart = this.$echarts.init(document.getElementById("bar-charts"));
      let option = {
           //--------  标题 title  --------
           title: {                               
               text: '主标题',  
               x: 'center',
               top: '10%',    //标题位置
               textStyle:{   //主标题内容样式   
                    fontSize: 30,
                    color:'#ccc'
               },
               subtext:'副标题',   
               subtextStyle:{    //副标题内容样式 
                    fontSize: 20,
                    color:'#ccc'               
               },
               padding:[0,0,100,100]     //标题位置,因为图形是是放在一个dom中,因此用padding属性来定位
            },
            //--------  图例 legend --------
            legend: {
               type:'plain',     //图例类型,默认为'plain',当图例很多时可使用'scroll'
               // top:'1%',      //图例相对容器位置,top\bottom\left\right      
               // left: '10px',  //图例位置
               orient: 'horizontal',    // orient 设置布局方式,默认水平布局,可选值:'horizontal'(水平) ¦ 'vertical'(垂直)
               x: 'left',    // x 设置水平安放位置,默认全图居中,可选值:'center' ¦ 'left' ¦ 'right' ¦ {number}(x坐标,单位px)
               y: 'top',     // y 设置垂直安放位置,默认全图顶端,可选值:'top' ¦ 'bottom' ¦ 'center' ¦ {number}(y坐标,单位px)
               selected:{
                   '销量':true,     //图例选择,图形加载出来会显示选择的图例,默认为true
               },
               textStyle:{    //图例内容样式
                   color:'#fff',     //所有图例的字体颜色
                   //backgroundColor:'black',  //所有图例的字体背景色
               },             
               tooltip:{        //图例提示框,默认不显示
                   show:true,
                   color:'red',
               },
               data:[        //----图例内容
                   {
                       name:'销量',
                       icon:'circle',   //----图例的外框样式
                       textStyle:{
                           color:'#fff',  //----单独设置某一个图例的颜色
                           //backgroundColor:'black',//---单独设置某一个图例的字体背景色
                       }
                   }
               ]                     
            },
            //---------   提示框 tooltip ----------
            tooltip: {
                show:true,                  //---是否显示提示框,默认为true
                trigger:'item',             //---数据项图形触发
                axisPointer:{               //---指示样式
                    type:'shadow',     
                    axis:'auto',   
                },  
                padding:5,
                textStyle:{                 //---提示框内容样式
                    color:"#fff",          
                },
            },
            //-------------   grid   -------------------
            grid: {  //设置图表div位置 可用百分数/具体px值
              top: "10%",     // 等价于 y: '10%'
              left: "10%",     // 等价于 x: '10%'
              right: "10%",
              bottom: "20%",
              containLabel: true
            },
            //-------------   x轴   -------------------
            xAxis: {
                show:true,                  //---是否显示
                position:'bottom',          //---x轴位置
                offset:0,                   //---x轴相对于默认位置的偏移
                type:'category',            //---轴类型,默认'category'
                name:'月份',              //---轴名称
                nameLocation:'end',         //---轴名称相对位置
                nameTextStyle:{             //---坐标轴名称样式
                    color:"#ccc",
                    padding:[5,0,0,-5], //---坐标轴名称相对位置
                },
                nameGap:15,                 //---坐标轴名称与轴线之间的距离
                //nameRotate:270,           //---坐标轴名字旋转
                data: ["2012", "2013", "2014", "2015", "2016", "2017"],
                axisLine:{                  //---坐标轴 轴线
                    show:true,                  //---是否显示
                    //------------------- 箭头 -------------------------
                    symbol:['none', 'arrow'],   //---是否显示轴线箭头
                    symbolSize:[8, 8] ,         //---箭头大小
                    symbolOffset:[0,7],         //---箭头位置
                    //------------------- 线 -------------------------
                    lineStyle:{
                        color:'#ccc',
                        width:1,
                        type:'solid',
                    },
                 },
                axisTick:{                  //---坐标轴 刻度
                    show:true,                  //---是否显示
                    inside:true,                //---是否朝内
                    lengt:3,                    //---长度
                    lineStyle:{
                        //color:'red',          //---默认取轴线的颜色
                        width:1,
                        type:'solid',
                    },
                  },
                axisLabel:{                 //---坐标轴 标签
                    show:true,                  //---是否显示
                    inside:false,               //---是否朝内
                    rotate:0,                   //---旋转角度  
                    margin: 5,                  //---刻度标签与轴线之间的距离
                    //color:'red',              //---默认取轴线的颜色
                },
                splitLine:{              //---grid 区域中的分隔线
                    show:false,          //---是否显示,'category'类目轴不显示,此时我的X轴为类目轴,splitLine属性是无意义的
                    lineStyle:{
                        //color:'red',
                        //width:1,
                        //type:'solid',
                    },
                },
                splitArea:{                 //--网格区域
                    show:false,            //--是否显示,默认false
                }
            },
            //-------------   y轴   -------------------
            yAxis: {
                show:true,                  //---是否显示
                position:'left',            //---y轴位置
                offset:0,                   //---y轴相对于默认位置的偏移
                type:'value',           //---轴类型,默认'category'
                name:'销量',              //---轴名称
                nameLocation:'end',         //---轴名称相对位置value
                nameTextStyle:{             //---坐标轴名称样式
                    color:"#ccc",
                    padding:[5,0,0,5],  //---坐标轴名称相对位置
                },
                nameGap:15,                 //---坐标轴名称与轴线之间的距离
                //nameRotate:270,           //---坐标轴名字旋转
                min:0, // 设置y轴刻度的最小值
                max:8000,  // 设置y轴刻度的最大值
                splitNumber:9,  // 设置y轴刻度间隔个数
                axisLine:{                  //---坐标轴 轴线
                    show:true,                  //---是否显示
                    //------------------- 箭头 -------------------------
                    symbol:['none', 'arrow'],   //---是否显示轴线箭头
                    symbolSize:[8, 8] ,         //---箭头大小
                    symbolOffset:[0,7],         //---箭头位置
                    //------------------- 线 -------------------------
                    lineStyle:{
                        color:'#ccc',
                        width:1,
                        type:'solid',
                    },
                },
                axisTick:{                  //---坐标轴 刻度
                    show:true,                  //---是否显示
                    inside:true,                //---是否朝内
                    lengt:3,                    //---长度
                    lineStyle:{
                        //color:'red',          //---默认取轴线的颜色
                        width:1,
                        type:'solid',
                    },
                },
                axisLabel:{                 //---坐标轴 标签
                    show:true,                  //---是否显示
                    inside:false,               //---是否朝内
                    rotate:0,                   //---旋转角度  
                    margin: 8,                  //---刻度标签与轴线之间的距离
                    //color:'red',              //---默认取轴线的颜色
                },
                splitLine:{                 //---grid 区域中的分隔线
                    show:true,                  //---是否显示,'category'类目轴不显示,此时我的y轴为类目轴,splitLine属性是有意义的
                    lineStyle:{
                        color:'#666',
                        width:1,
                        type:'dashed',          //---类型
                    },
                },
                splitArea:{                 //--网格区域
                    show:false,                 //---是否显示,默认false
                }      
            },
            //------------ 内容数据  -----------------
            series: [
                {
                    name: '销量',             //---系列名称
                    type: 'bar',                //---类型 bar 柱状图;line 折线图
                    legendHoverLink:true,       //---是否启用图例 hover 时的联动高亮
                    label:{                     //---图形上的文本标签
                        show:false,
                        position:'insideTop',   //---相对位置
                        rotate:0,               //---旋转角度
                        color:'#eee',
                    },
                    itemStyle:{                 //---图形形状
                        color:'blue',
                        barBorderRadius:[18,18,0,0],
                    },
                    barWidth:'20%',              //---柱形宽度
                    barCategoryGap:'20%',       //---柱形间距
                    data: [3020, 4800, 3600, 6050, 4320, 6200]
                },
                {
                    name: '假设',
                    type: 'line',
                    // 设置折线上圆点大小
                    symbolSize:10,
                    // 设置拐点为实心圆
                    symbol:'circle',            
                    itemStyle: {
                        normal: {
                            label : {
                                show: true    // 拐点上显示数值
                            },
                            lineStyle:{
                                color: 'rgba(0,0,0,0)'    // 使用rgba设置折线透明度为0,可以视觉上隐藏折线
                            }
                        },
                    },
                    data: [120, 232, 541, 134, 290, 130]
                },
            ]
        };
        // 绘制图表
        myChart.setOption(option);
    

    相关文章

      网友评论

          本文标题:echarts 柱状图/折线图相关属性设置

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