echarts 折线统计图

在这里插入图片描述
页面html代码

    <!--道路及沿线设备病害统计-->
    <div class="layui-col-md12 layui-col-lg6">
      <div echarts id="roadDevice" class="demo-chart demo-color"
           style="margin-top: 20px;width: 100%;height: 400px;"></div>
    </div>
    <!--巡查、病害、养护数量统计-->
    <div class="layui-col-md12 layui-col-lg6">
      <div echarts id="inspectDiseaseCuring" class="demo-chart demo-color demo-float"
           style="margin-top: 20px;width: 100%;height: 400px;"></div>
    </div>

css

.demo-float{
  float: right;
}
.demo-color{
  background-color: #fff;
  max-width: 97%;
  font-family: sans-sarif;
  font-size: 9px;
  font-weight: 300;
  margin:10px ;

}

js代码
图一代码

  //道路及沿线设备病害统计图表
  getRoadDeviceEcharts() {
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById('roadDevice'));

    var roadData = [];
    var deviceData = [];

    for (var i = 0; i < 10; i++) {
      roadData.push((Math.random() * 2).toFixed(2));
      deviceData.push((Math.random() * 5).toFixed(2));
    }
    // 指定图表的配置项和数据
    const option = {
      title: {
        top: '5%',
        text: '道路及沿线设备病害统计'
      },
      legend: {
        data: ['道路', '设备'],
        left: '60%',
        top: '20',
      },
      tooltip: {
        trigger: 'axis',
      },
      // brush: {
      //   toolbox: [],
      //   xAxisIndex: 0
      // },
      toolbox: {
        feature: {
          magicType: {
            type: ['stack', 'tiled']
          },
          dataView: {}
        }
      },

      xAxis: {
        type: 'category',
        data: this.timeList
      },

      yAxis: {
        type: 'value'
      },
      grid: {
        // bottom: 100
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },

      series: [
        {
          name: '道路',
          type: 'bar',
          stack: 'one',
          color: '#0babff',
          lineStyle: {  //线的颜色
            color: '#0babff'
          },
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: { //数值样式
                color: '#0babff',
                fontSize: 9
              }
            }
          },
          data: roadData
        },
        {
          name: '设备',
          type: 'bar',
          stack: 'one',
          color: '#8CE24F',
          lineStyle: {  //线的颜色
            color: '#8CE24F'
          },
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: { //数值样式
                color: '#8CE24F',
                fontSize: 9
              }
            }
          },
          data: deviceData
        },
      ]
    };
    myChart.on('brushSelected', renderBrushed);

    function renderBrushed(params) {
      var brushed = [];
      var brushComponent = params.batch[0];

      for (var sIdx = 0; sIdx < brushComponent.selected.length; sIdx++) {
        var rawIndices = brushComponent.selected[sIdx].dataIndex;
        brushed.push('[Series ' + sIdx + '] ' + rawIndices.join(', '));
      }

      myChart.setOption({
        title: {
          backgroundColor: '#333',
          text: 'SELECTED DATA INDICES: \n' + brushed.join('\n'),
          bottom: 0,
          right:'10%',
          width: 100,
          textStyle: {
            fontSize: 12,
            color: '#fff'
          }
        }
      });
    }
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

  }

图二代码

  //巡查、病害、养护数量统计图表
  getInspectDiseaseCuringEcharts() {
    // let myChart = echarts.init(document.getElementById('paishui2'+ pumpId));
    let myChart = null;
    // this.ngZone.runOutsideAngular(() => {
    myChart = echarts.init(document.getElementById('inspectDiseaseCuring'));
    // });

    const ps2option = {
      title: {
        top: '5%',
        // text: '巡查、病害、养护数量统计'
        text: '病害、养护数量统计'
      },
      tooltip: {
        trigger: 'axis',
      },
      legend: {
        left: '60%',
        top: '20',
        data: ['病害数量', '养护数量'],

      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        // data: timeList.map(function (str) {
        //   return str.replace(' ', '\n');
        // }),
        data: this.timeList
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: '病害数量',
          type: 'line',
          stack: '总量',
          color: '#0babff',
          lineStyle: {  //线的颜色
            color: '#0babff'
          },
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: { //数值样式
                color: '#0babff',
                fontSize: 9
              }
            }
          },
          areaStyle: {
            color: 'rgba(11,171,255,0.5)'
          },
          emphasis: {
            focus: 'series'
          },
          // data: avgDrainageSpeedList,
          data: [320, 332, 301, 334, 390, 330, 320],
        },
        {
          name: '养护数量',
          type: 'line',
          stack: '总量',
          color: '#5ADC5B',
          lineStyle: {  //线的颜色
            color: '#5ADC5B'
          },
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: { //数值样式
                color: '#5ADC5B',
                fontSize: 9,
              }
            }
          },
          areaStyle: {
            color: 'rgba(90,220,91,0.5)'
          },
          emphasis: {
            focus: 'series'
          },
          // data: drainageList,
          data: [820, 932, 901, 934, 1290, 1330, 1320],
        }
      ]
    };
    // 绘制图表
    myChart.clear(); //清楚之前echarts 缓存 重新画折线图
    myChart.setOption(ps2option);

  }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECharts 是百度开源的一个基于 JavaScript 的数据可视化库,可以用于创建各种类型的表,包括折线。下面是关于 ECharts 折线的详解: 1. 折线概述:折线是一种常用的统计表,用于显示数据随时间或其他连续变量的变化趋势。折线由一系列连续的数据点通过线段连接而成,可以直观地展示数据的波动情况。 2. 折线的应用场景:折线适用于多种场景,比如股票指数走势、气温变化、销售额趋势等等。通过折线,可以清晰地展示数据的变化规律,帮助用户做出合理的决策。 3. ECharts 中创建折线:使用 ECharts 创建折线非常简单。首先引入 ECharts 的库文件,然后创建一个容器元素用来放置表,最后通过配置项和数据来定义折线的样式和数据源。你可以在 ECharts 官网上找到详细的文档和示例代码来学习如何使用 ECharts 创作折线。 4. 折线的主要配置项: - xAxis:横轴配置项,用于定义横轴的类型、刻度等。 - yAxis:纵轴配置项,用于定义纵轴的类型、刻度等。 - series:系列配置项,用于定义折线的数据和样式。 - tooltip:提示框配置项,用于显示鼠标悬停在折线上时的数据信息。 - legend:例配置项,用于标识折线中不同系列的含义。 5. 折线的样式设置:ECharts 支持灵活的样式定制,可以通过配置项来调整折线的颜色、线型、标记点形状等。你可以根据自己的需求来选择合适的样式,使折线更加美观与易读。 总结:ECharts 提供了丰富而强大的功能,能够轻松地创建出各种类型的表,包括折线。通过使用 ECharts,你可以展示数据的趋势和变化规律,帮助用户更好地理解数据并作出决策。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值