美文网首页
echarts折线图横纵坐标颜色配置

echarts折线图横纵坐标颜色配置

作者: 明眸yh | 来源:发表于2020-10-19 16:02 被阅读0次

今天配合ios端做了一个折线图h5页面,其中有一些样式需要调整总结如下:


原图
UI

需要需改坐标轴的颜色和紫的颜色,折线的颜色

坐标轴颜色

// 设置坐标轴字的颜色
axisLabel: {
   color: '#666669'
},
splitLine: {
   lineStyle: {
      color: "#EEEEF1"
   }
},
axisLine: {
   lineStyle: {
      type: 'solid',
      color: '#EEEEF1',//左边线的颜色
      width:'1'//坐标线的宽度
   }
}
坐标线

缩放

dataZoom: [{
    show: true,
    type: 'inside',
    filterMode: 'none',
    xAxisIndex: [0],
    startValue: 0,
     endValue: 20
  }, {
    show: true,
    type: 'inside',
    filterMode: 'none',
    yAxisIndex: [0],
    startValue: 0,
    endValue: 20
}],

设置折线线条颜色

series: [{
   itemStyle : {
       normal : {
          lineStyle:{
              color:'#FF4A4A'
          }
       }
   }   
 }]
线条

这样就实现了
整体代码如下: (只是一个demo)

<!--
 * @Descripttion: 
 * @version: 
 * @Author: yanghui
 * @Date: 2020-10-19 14:01:20
 * @LastEditors: yanghui
 * @LastEditTime: 2020-10-19 15:59:38
-->
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport"
    content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <title>折线图</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      background-color: #fff;
    }
  </style>

  <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
</head>

<body>

  <div id="main" style="width: 100%;height:503px;
    overflow: hidden;"></div>

  <script type="text/javascript">
    function showLine(str) {
      console.log(str)
      var edata = JSON.parse(str);
      
      var myChart = echarts.init(document.getElementById('main'));

      // 图表的配置项和数据
      var option = {
        
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        toolbox: {
          show: false,
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisLine: {
            color: '#666669',
            lineStyle: {
              type: 'solid',
              color: '#EEEEF1',//左边线的颜色
              width:'1'//坐标线的宽度
            }
          },
          
          axisLabel: {
            color: '#666669'
          },
          data: edata.arr1
        },
        yAxis: {
          name: 'mm/s',
          type: 'value',
          axisLabel: {
            formatter: '{value} ',
            color: '#666669'
          },
          splitLine: {
            lineStyle: {
              color: "#EEEEF1"
            }
          },
          axisLine: {
            color: '#666669',
            lineStyle: {
              type: 'solid',
              color: '#EEEEF1',//左边线的颜色
              width:'1'//坐标线的宽度
            }
          },
          axisPointer: {
            snap: true
          }
        },
        visualMap: {
          show: false,
          dimension: 0
        },
        series: [{
          itemStyle : {
            normal : {
              lineStyle:{
                color:'#FF4A4A'
              }
            }
          },
          name: 'Hz',
          type: 'line',
          smooth: true,
          data: edata.arr2,
        }]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);

    }
    let data = {
      arr1: [10, 20,50,100, 200,300,350,400,500,600,700],
      arr2: [23,25,30,40,70,67,55,24,44,55,12]
      //初始化echart
    }
    let str = JSON.stringify(data)
    showLine(str)
  </script>
</body>

</html>

感谢您

  • 如果觉得这篇文章对您有帮助的话,动一动小手点着赞吧
  • 有问题可关注我的公众号 前端小喵,回复“加入”加我微信,我们一起交流学习,回复“教程”,即可领取免费前端教程资源。

相关文章

网友评论

      本文标题:echarts折线图横纵坐标颜色配置

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