vue+echarts 多功能折线图示例

1、安装echarts模块

npm install echarts --save

2、新建vue文件, 示例程序主体来自echarts官网:https://echarts.apache.org/examples/zh/index.html#chart-type-line

<template>
  <div id="app">
    <!--为echarts准备一个具备大小的容器dom-->
    <div id="main" style="width: 1200px; height: 400px"></div>
  </div>
</template>
<script>
// import echarts from 'echarts'
import * as echarts from 'echarts'
export default {
  name: '',
  data() {
    return {
      charts: '',
      opinionData: [['2000-06-05', 116], ['2000-06-06', 129], ['2000-06-07', 135], ['2000-06-08', 86], ['2000-06-09', 73], ['2000-06-10', 85], ['2000-06-11', 73], ['2014-06-17', 104], ['2014-06-18', 116], ['2014-06-19', 116], ['2014-06-20', 84], ['2014-06-21', 96], ['2014-06-22', 91], ['2014-06-23', 115], ['2014-06-24', 161], ['2014-06-25', 138], ['2014-06-26', 163], ['2014-06-27', 68], ['2014-06-28', 77], ['2014-06-29', 161], ['2014-06-30', 185], ['2014-07-01', 172], ['2014-07-02', 80], ['2014-07-03', 248], ['2014-07-04', 237], ['2014-07-05', 165], ['2014-07-06', 256], ['2014-07-07', 216], ['2014-07-08', 134], ['2014-07-09', 63], ['2014-07-10', 114], ['2014-07-11', 77], ['2014-07-12', 80], ['2014-07-13', 64], ['2014-07-14', 156], ['2014-07-15', 140], ['2014-07-16', 133], ['2014-07-17', 186], ['2014-07-18', 182], ['2014-07-19', 106], ['2014-07-20', 119], ['2014-07-21', 68], ['2014-07-22', 54], ['2014-07-23', 82], ['2014-07-24', 90], ['2014-07-25', 134], ['2014-07-26', 188], ['2014-07-27', 194], ['2014-07-28', 159], ['2014-07-29', 159], ['2014-07-30', 169], ['2014-07-31', 244], ['2014-08-01', 199], ['2014-08-02', 163], ['2014-08-03', 149], ['2014-08-05', 80], ['2014-08-06', 67], ['2014-08-07', 162], ['2014-08-08', 140], ['2014-08-09', 143], ['2014-08-10', 125], ['2014-08-11', 76], ['2014-08-12', 119], ['2014-08-13', 70], ['2014-08-14', 104], ['2014-08-15', 109], ['2014-08-16', 159], ['2014-08-17', 124], ['2014-08-18', 135], ['2014-08-19', 150], ['2014-08-20', 164], ['2014-08-21', 169], ['2014-08-22', 83], ['2014-08-23', 155], ['2014-08-24', 75], ['2014-08-25', 59], ['2014-08-26', 78], ['2014-08-27', 136], ['2014-08-28', 103], ['2014-08-29', 104], ['2014-08-30', 176], ['2014-08-31', 89], ['2014-09-01', 127], ['2014-09-03', 54], ['2014-09-04', 100], ['2014-09-05', 140], ['2014-09-06', 186], ['2014-09-07', 200], ['2014-09-08', 61], ['2014-09-09', 109], ['2014-09-10', 111], ['2014-09-11', 114], ['2014-09-12', 97], ['2014-09-13', 94], ['2014-09-14', 66], ['2014-09-15', 54], ['2014-09-16', 87], ['2014-09-17', 80], ['2014-09-18', 84], ['2014-09-19', 117], ['2014-09-20', 168], ['2014-09-21', 129], ['2014-09-22', 127], ['2014-09-23', 64], ['2014-09-24', 60], ['2014-09-25', 144], ['2014-09-26', 170], ['2014-09-27', 58], ['2014-09-28', 87], ['2014-09-29', 70], ['2014-09-30', 53], ['2014-10-01', 92], ['2014-10-02', 78], ['2014-10-03', 123], ['2014-10-04', 95], ['2014-10-05', 54], ['2014-10-06', 68], ['2014-10-07', 200], ['2014-10-08', 314], ['2014-10-09', 379], ['2014-10-10', 346], ['2014-10-11', 233], ['2014-10-14', 80], ['2014-10-15', 73], ['2014-10-16', 76], ['2014-10-17', 132], ['2014-10-18', 211], ['2014-10-19', 289], ['2014-10-20', 250], ['2014-10-21', 82], ['2014-10-22', 99], ['2014-10-23', 163], ['2014-10-24', 267], ['2014-10-25', 353], ['2014-10-26', 78], ['2014-10-27', 72], ['2014-10-28', 88], ['2014-10-29', 140], ['2014-10-30', 206], ['2014-10-31', 204], ['2014-11-01', 65], ['2014-11-03', 59], ['2014-11-04', 150], ['2014-11-05', 79], ['2014-11-07', 63], ['2014-11-08', 93], ['2014-11-09', 80], ['2014-11-10', 95], ['2014-11-11', 59], ['2014-11-13', 65], ['2014-11-14', 77], ['2014-11-15', 143], ['2014-11-16', 98], ['2014-11-17', 64], ['2014-11-18', 93], ['2014-11-19', 282], ['2014-11-23', 155], ['2014-11-24', 94], ['2014-11-25', 196], ['2014-11-26', 293], ['2014-11-27', 83], ['2014-11-28', 114], ['2014-11-29', 276], ['2014-12-01', 54], ['2014-12-02', 65], ['2014-12-03', 51], ['2014-12-05', 62], ['2014-12-06', 89], ['2014-12-07', 65], ['2014-12-08', 82], ['2014-12-09', 276], ['2014-12-10', 153], ['2014-12-11', 52], ['2014-12-13', 69], ['2014-12-14', 113], ['2014-12-15', 82], ['2014-12-17', 99], ['2014-12-19', 53], ['2014-12-22', 103], ['2014-12-23', 100], ['2014-12-25', 73], ['2014-12-26', 155], ['2014-12-27', 243], ['2014-12-28', 155], ['2014-12-29', 125], ['2014-12-30', 65], ['2015-01-01', 65], ['2015-01-02', 79], ['2015-01-03', 200], ['2015-01-04', 226], ['2015-01-05', 122], ['2015-01-06', 60], ['2015-01-07', 85], ['2015-01-08', 190], ['2015-01-09', 105], ['2015-01-10', 208], ['2015-01-11', 59], ['2015-01-12', 160], ['2015-01-13', 211], ['2015-01-14', 265], ['2015-01-15', 386], ['2015-01-16', 118], ['2015-01-17', 89], ['2015-01-18', 94], ['2015-01-19', 77], ['2015-01-20', 113], ['2015-01-22', 143], ['2015-01-23', 257], ['2015-01-24', 117], ['2015-01-25', 185], ['2015-01-26', 119], ['2015-01-28', 65], ['2015-01-29', 87], ['2015-01-31', 60], ['2015-02-01', 108], ['2015-02-02', 188], ['2015-02-03', 143], ['2015-02-05', 62], ['2015-02-06', 100], ['2015-02-09', 152], ['2015-02-10', 166], ['2015-02-11', 55], ['2015-02-12', 59], ['2015-02-13', 175], ['2015-02-14', 293], ['2015-02-15', 326], ['2015-02-16', 153], ['2015-02-18', 73], ['2015-02-19', 267], ['2015-02-20', 183], ['2015-02-21', 394], ['2015-02-22', 158], ['2015-02-23', 86], ['2015-02-24', 207]]
    }
  },
  methods: {
    drawLine(id) {
      this.charts = echarts.init(document.getElementById(id))
      this.charts.setOption({
        title: {
          text: 'Beijing AQI',
          left: '1%'
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          left: '5%',
          right: '15%',
          bottom: '10%'
        },
        xAxis: {
          data: this.opinionData.map(function (item) {
            return item[0]
          })
        },
        yAxis: {},
        toolbox: {
          right: 10,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            restore: {},
            saveAsImage: {}
          }
        },
        dataZoom: [
          {
            startValue: '2014-06-01'
          },
          {
            type: 'inside'
          }
        ],
        visualMap: {
          top: 50,
          right: 10,
          pieces: [
            {
              gt: 0,
              lte: 50,
              color: '#93CE07'
            },
            {
              gt: 50,
              lte: 100,
              color: '#FBDB0F'
            },
            {
              gt: 100,
              lte: 150,
              color: '#FC7D02'
            },
            {
              gt: 150,
              lte: 200,
              color: '#FD0100'
            },
            {
              gt: 200,
              lte: 300,
              color: '#AA069F'
            },
            {
              gt: 300,
              color: '#AC3B2A'
            }
          ],
          outOfRange: {
            color: '#999'
          }
        },
        series: {
          name: 'Beijing AQI',
          type: 'line',
          data: this.opinionData.map(function (item) {
            return item[1]
          }),
          markLine: {
            silent: true,
            lineStyle: {
              color: '#333'
            },
            data: [
              {
                yAxis: 50
              },
              {
                yAxis: 100
              },
              {
                yAxis: 150
              },
              {
                yAxis: 200
              },
              {
                yAxis: 300
              }
            ]
          }
        }
      })
    }
  },
  // 调用
  mounted() {
    this.$nextTick(function () {
      this.drawLine('main')
    })
  }
}
</script>
<style scoped>
</style>

3、启动

npm run serve

4、效果图

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,558评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,002评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,024评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,144评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,255评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,295评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,068评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,478评论 1 305
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,789评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,965评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,649评论 4 336
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,267评论 3 318
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,982评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,223评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,800评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,847评论 2 351