Echarts 实现折线图

<!-- 容器必须要有高度,宽度可选-->
<div id="main" style="height: 400px"></div>


<script src="./echarts-5.3.3.js"></script>
<script>
  // (图表挂载的对象, 主题样式, 渲染方式)
  var myChart = echarts.init(document.getElementById("main"), null, {
      renderer: 'svg'
  });

  var option = {
    backgroundColor: "rbg(40,46,72)", 
    grid: {    // 网格
      show: true,  
      left: "5%",
      right: "1%",
      top: "20%",
      bottom: "15%",
      containLabel: true, // grid 区域是否包含坐标轴的刻度标签
    },
    legend: {  // 图例
      top: 20,
      right: 20,
      itemGap: 20,
      itemWidth: 13,
      itemHeigth: 12,
      textStyle: {
        color: "#64BCFF",
      },
      icon: "rect",  // 图例样式为矩形
    },
    tooltip: {    // 注释标签
      trigger: "axis",   // 触发类型 
                // 'item'  数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用
                // 'axis'  坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用
      axisPointer: {  // 坐标轴指示器配置项
        type: "line",
        lineStyle: {
          color: "#20FF89",
        },
      },
    },
    xAxis: [
      {
        type: "category",
        axisLine: {
          show: false,
        },
        axisLabel: {
          color: "#64BCFF",
          interval: 2  // x轴的label 以2为间隔显示
        },
        boundaryGap: false, // x轴第一列的数据挨着y轴
        data: [
          "1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月",
        ],
      },
    ],
    yAxis: [
      {
        name: "单位: 元",
        type: "value",
        axisLabel: {
          show: true,
          color: "#64BCFF",
        },
        splitLine: {
          show: true,
          lineStyle: {
            color: 'lightblue'
          }
        }
      },
    ],
    series: [
      {
        name: "曲线",
        type: "line",
        smooth: true,  // 平滑显示
        symbolSize: 10, // 标记节点的大小
        showSymbol: false,  // 显示item节点
        itemStyle: {
          color: "#20FF89",
        },
        symbol:'rect',   // 节点的形状
        areaStyle: { 
          color: new echarts.graphic.LinearGradient(
            0,
            0,
            0,
            1,
            [
              {
                offset: 0,
                color: "#20FF89",
              },
              {
                offset: 1,
                color: "rgba(255, 255, 255, 0)",
              },
            ],
            false
          ),
        },
        data: [200, 200, 191, 234, 290, 330, 310, 201, 154, 190, 330, 410],
      },
      {
        name: "折线",
        type: "line",
        symbolSize: 5, 
        showSymbol: true,
        itemStyle: {
          color: "#EA9502",
        },
        emphasis: {
          scale: 4   // 是否开启 hover 在拐点标志上的放大效果
        },
        areaStyle: {
          color: {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: "#EA9502",
              },
              {
                offset: 1,
                color: "rgba(255, 255, 255, 0)",
              },
            ],
          },
        },
        data: [500, 300, 202, 258, 280, 660, 320, 202, 308, 280, 660, 420],
      },
    ],
  }; 
  myChart.setOption(option);
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值