echarts折线图x轴垂直对齐,y轴对齐数值,网格变虚线,x轴折线背景渐变,改变折线图长宽,饼图上下分布和左右分布,条形图上下分布

先放效果图,是需要的再往下看
在这里插入图片描述

getChart() {
      let _chart = echarts.init(document.getElementById('Chartid'))
      let option = {
        legend: {
          right: 12,
          top: 10,
          data: [
            {
              name: '名字',
              icon: 'circle',              
            }
          ],
        },
        grid:{
        // 修改图的长和宽
          width: '84%',
          height: '60%'
        },
        xAxis: {
          name: '月',
          nameGap: 8,          
          nameTextStyle: {
            verticalAlign: 'top',
            lineHeight: 28,   // 调整x轴名字的位置,和x轴值对齐
          },
          boundaryGap: false,
          axisLine: {  
            show: false,
          },
          axisTick: {
            show: false,
          },          
          type: 'category',          
          data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
        },
        yAxis: {
          name: '万吨',
          type: 'value',
          splitLine: {
            lineStyle: {
              type: 'dashed', // 网格线虚线
            },
          },
          nameTextStyle: {
            padding: [0, 40, 0, 0],  // y轴名字对齐刻度值
          },
        },
        series: [
          {
            name: 'name',
            type: 'line',
            symbolSize: 0,
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                // 渐变
                  0, 0, 0, 1, [
                  { offset: 0, color: 'rgba(84, 112, 198, 0.8)' },
                  { offset: 0.4, color: 'rgba(84, 112, 198, 0.2)' },
                  { offset: 1, color: 'rgba(84, 112, 198, 0.01)' },
                  ]
                ),
              },
            },
            data: [120, 132, 201, 134, 90, 230, 210, 120,800, 101, 134, 90, 230],
          },
        ],
      }
      option && _chart.setOption(option)
    },

多组数据的时候,在数组series中增加其他对象。
在legend.data中增加其他图例对象

关于坐标轴和legend相互位置设置:

  • 1.左右分布
    设置legend横坐标位置靠右吗,设置偏移大小

效果图
在这里插入图片描述

 legend: {
          align: 'left',
          icon: 'circle',
          orient: 'vertical',
          x: 'right'
          }

 series: {
 			type: 'pie',
            size: '84%',
            center: ['28%', '50%'
           }
  • 上下分布:
    1.饼图
    设置series偏移的大小
        legend: {
          bottom: 18
          }
 		series: {
 		  type: 'pie',
          center: ['50%', '40%']
          }

2.条形图。
定位网格高度和距离边距的距离,定位legend距离底边的距离

//  type: 'bar',
        grid: {
          height: '80%',
          left: '30%',
          top: '10%'
        },
        legend:{
          bottom: '1%',
          icon: 'rect',          
        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值