先给大家看图

父组件

     <el-container v-show="abscissa">
        <lineEchart
          :CPUInfoList="CPUTotalUsage"
          :Timer="Timer"
          :abscissa="abscissa"
          :ordinate="ordinate"
          :title="title[0]"
          :titleList="titleList[0]"
          :unit="unit[0]"
        ></lineEchart>
      </el-container>
  components: {
    lineEchart
  },
上面是DOM和组件注册
  CPUTotalUsage: '',
  Timer: '',
  abscissa: [],
// 折线纵轴单位
unit: ['%', 'Mbps'],
// 折线title
title: ['教师端系统指标', '其他指标', 'TOP5进程占用-CPU', 'TOP5进程占用-内存'],
    ordinate: [],
上面这些是data里面定义的数据 下面是请求到的数据
.then(res => {
        if (res.Status == 1) {
          this.dataList = res.Content
          if (this.dataList) {
            this.dataList.forEach(item => {
              if (item.Datetime == this.Timer) {
                this.CPUTotalUsage = item.CPUProcessUsage
              }
              this.abscissa.push(item.Datetime)
              this.ordinateList.CPUTotalUsage.push(item.CPUTotalUsage)
              this.ordinateList.CPUProcessUsage.push(item.CPUProcessUsage)
              this.ordinateList.MemTotalUsage.push(item.MemTotalUsage)
              this.ordinateList.MemProcessUsage.push(item.MemProcessUsage)
              this.ordinateList.GPUTotalUsage.push(item.GPUTotalUsage)
              this.ordinateList.GPUMemUsage.push(item.GPUMemUsage)
              this.ordinateList.FPS.push(item.FPS)
              this.ordinateList.NetworkRecvSpeed.push(item.NetworkRecvSpeed)
              this.ordinateList.NetworkSendSpeed.push(item.NetworkSendSpeed)
            })
            this.ordinate = [
              {
                name: '系统CPU总占用',
                data: this.ordinateList.CPUTotalUsage
              },
              {
                name: '应用CPU占用',
                data: this.ordinateList.CPUProcessUsage
              },
              {
                name: '系统内存总占用',
                data: this.ordinateList.MemTotalUsage
              },
              {
                name: '应用内存占用',
                data: this.ordinateList.MemProcessUsage
              },
              {
                name: '系统GPU总占用',
                data: this.ordinateList.GPUTotalUsage
              },
              {
                name: '系统显存总占用',
                data: this.ordinateList.GPUMemUsage
              }
            ]
          } else {
            this.loading = false
            this.showFlag = false
          }
        } else {
          this.showFlag = false
          this.$message({
            message: res.Msg,
            type: 'error'
          })
        }
      })

我们看下返回的数据都是什么

这是整个接口的返回  我们就取一些数据

这个就是子组件echarts的组件实例

<template>
  <div class="echarts" ref="echarts"></div>
</template>
<script>
import echarts from 'echarts'
import wonderland from './echarts'
export default {
  props: {
    abscissa: {
      type: Array,
      default: () => []
    },
    ordinate: {
      type: Array,
      default: () => []
    },
    title: String,
    titleList: {
      type: Array,
      default: () => []
    },
    unit: String,
    Timer: String,
    CPUInfoList: String
  },
  data() {
    return {
      chart: null,
      myChart: null,
      option: {},
      lineList: []
    }
  },
  mounted() {},
  watch: {
    abscissa(newV, oldV) {
      this.draw()
    }
  },
  methods: {
    draw() {
      this.chart = this.$refs.echarts
      this.chart.style.width = document.documentElement.clientWidth - 200 + 'px'
      this.chart.style.height = 300 + 'px'
      echarts.init(this.chart, 'wonderland').dispose()
      echarts.registerTheme('wonderland', wonderland)
      this.myChart = echarts.init(this.chart, 'wonderland')
      this.option = {
        title: {
          text: this.title
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        legend: {
          data: this.titleList
        },
        toolbox: {
          feature: {}
        },
        grid: {
          left: '5%',
          right: '4%',
          bottom: '10%',
          containLabel: false
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: this.abscissa
          }
        ],
        yAxis: [
          {
            type: 'value',
            axisLabel: {
              formatter: '{value}' + this.unit
            }
          }
        ],
        dataZoom: [
          {
            type: 'slider',
            show: true,
            xAxisIndex: [0],
            start: 0,
            end: 100
          },
          {
            type: 'inside',
            xAxisIndex: [0],
            start: 0,
            end: 100
          }
        ],
        series: []
      }
      var this_ = this
      echarts.util.each(this.ordinate, function(item, index) {
        this_.option.series.push({
          name: item.name,
          type: 'line',
          showSymbol: false,
          sampling: 'average',
          data: item.data,
          markPoint: {
            symbolSize: this_.CPUInfoList ? 60 : 0,
            data: [
              {
                name: '某个坐标',
                yAxis: this_.CPUInfoList,
                xAxis: this_.Timer,
                value: '崩溃点'
              }
            ]
          }
        })
      })
      this.myChart.setOption(this.option)
      this.myChart.group = '1'
      echarts.connect('1')
      window.addEventListener('resize', () => {
        this.myChart.resize()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.echarts {
  // width: 100%;
  height: 500px;
}
</style>

echarts做折线图的更多相关文章

  1. echarts版本折线图

    1.效果如下:         绘制折线图,应该算是说echarts中使用最简单也算使用频率最高的一种功能了吧.根据官网列子能找出规律,只是有些属性对于初接触者来说,会有点陌生,不过仔细阅读一下还是不 ...

  2. Echarts line折线图使用(vue)

    实现 首先引入echarts工具 // vue文件中引入echarts工具 let echarts = require('echarts/lib/echarts') require('echarts/ ...

  3. ECharts使用—折线图动态加载

    最近需求中用到折线图,单线条,多线交错,之前是散点图,用的是另一个 amcharts.js,这个文档也能找的到,回归早本次重点:ECharts 一.首先引入echarts.common.min.js文 ...

  4. 移动端引用echarts的折线图

          移动端写一个图表引用echarts,highcharts插件,本次要找一个能够显示最新数据的折线图,最后只找到显示最大值: 找到echarts的实例:记一下个各功能.   <!DOC ...

  5. echarts实现折线图

    前端框架使用的angular,折线图使用echarts实现. 这里实现的折线图只是简单是折线图,折线图显示在table中,不需要xy轴的数据说明. 1. item.component.html < ...

  6. Echarts案例-折线图

    一:先在官网下载 https://www.echartsjs.com/zh/download.html 然后再建立工程,导入这两个包: 写代码: <!DOCTYPE html> <h ...

  7. echarts自定义折线图横坐标时间间隔踩坑总结

    折线图需求:横坐标为时间,要求按一定间隔展示,鼠标移至折线上间隔时间内的数据也可展示 其实很简单的一个配置就可搞定,但在不熟悉echarts配置的情况下,就很懵逼 xAxis: { boundaryG ...

  8. echarts之折线图介绍及使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 使用Echarts实现折线图的一点总结

    使用Echarts的一点总结 1.安装,我使用得vue cnpm install echarts --save 2.在入口文件main.js中注册,并使用 // 引入折线图 echarts impor ...

  10. ECharts绘制折线图

    首先看实现好的页面 实现 首先引入echarts工具 // vue文件中引入echarts工具 let echarts = require('echarts/lib/echarts') require ...

随机推荐

  1. Django框架——模版层之标签、自定义过滤器 标签及inclusion_tag(了解)、模版的继承与导入、模型层之前期准备、ORM常用关键字

    模版层之标签 {% if 条件1(可以自己写也可以用传递过来的数据) %} <p>今天又是周三了</p> {% elif 条件2(可以自己写也可以用传递过来的数据) %} &l ...

  2. Java实现查看手机配置与功能

    "感谢您阅读本篇博客!如果您觉得本文对您有所帮助或启发,请不吝点赞和分享给更多的朋友.您的支持是我持续创作的动力,也欢迎留言交流,让我们一起探讨技术,共同成长!谢谢!" 代码 `` ...

  3. 力扣476(java)-数字的补数(简单)

    题目: 对整数的二进制表示取反(0 变 1 ,1 变 0)后,再转换为十进制表示,可以得到这个整数的补数. 例如,整数 5 的二进制表示是 "101" ,取反后得到 "0 ...

  4. 暑期集训 Day5 —— 模拟赛复盘

    ${\color{Green} \mathrm{Problem\ 1 :选数 }} $ 签到题,一眼二分,但是打模板时死循环了: while(L<R){ int mid=(L+R)>> ...

  5. 102万行代码,1270 个问题,Flink 新版发布了什么?

    阿里妹导读: Apache Flink 是公认的新一代开源大数据计算引擎,可以支持流处理.批处理和机器学习等多种计算形态,也是Apache 软件基金会和 GitHub 社区最为活跃的项目之一. 201 ...

  6. 运行程序时报go: cannot find main module, but found .git/config in

    编写单元测试,运行时报下面的错误 haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi0 ...

  7. vim简明文档

    替换 替换当前行第一个 :s/vivian/sky/ 替换当前行第一个 vivian 为 sky 从当前行替换到最后一行 :%s/vivian/sky/g 替换所有行中 vivian 为 sky 查找 ...

  8. leaflet 使用kriging.js实现前端自定义插值

    1.GitHub地址:https://github.com/oeo4b/kriging.js 2.核心代码 var variogram = kriging.train(t, x, y, model, ...

  9. CSRF(Pikachu靶场练习)

    CSRF(get) 自己随便输点东西,回显登录失败,查看源码没发现什么 点开提示,登录进去看看 看到可以修改个人信息,我们把居住改成China,修改成功,没发现urlhttp://127.0.0.1/ ...

  10. Splashtop 支持对 Adobe Creative Cloud 视频应用程序的远程访问

    快讯:Splashtop 为 Adobe Creative Cloud 视频和音频产品的用户提供了对其工作站的高性能远程访问,使他们能够在家中工作. 程访问和远程支持解决方案的领导者 Splashto ...