echarts系列-----1

7 篇文章 0 订阅

本篇讲解最简单的echarts实现方法,具体见代码,并标注注释(例子 文档事例都是有的,传送门?

在这里插入图片描述

<template>
  <div>
    <div id="main" style="width:1200px;height:600px;"></div>
  </div>
</template>

<script>
import echarts from "echarts";
export default {
  name: "echartssimple",
  data() {
    return {
      list: [
        {
          x: 1,
          y: 1
        },
        {
          x: 2,
          y: 2
        },
        {
          x: 3,
          y: 3
        },
        {
          x: 4,
          y: 4
        },
        {
          x: 5,
          y: 1
        },
        {
          x: 6,
          y: 0
        },
        {
          x: 7,
          y: 10
        }
      ],
      dataX: [],
      dataY: []
    };
  },
  methods: {
    init() {
      this.myChart = echarts.init(document.getElementById("main"));
      let option = {
        legend: {
          icon: "stack",
          data: ["AA"]
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            animation: true
          }
        },
        // 工具栏
        toolbox: {
          x: 1100,
          y: 0,
          feature: {
            saveAsImage: {
              name: `test` // 下载图片
            }
          }
        },
        grid: {
          left: "5%", //组件距离容器左边的距离
          right: "20%",
          top: "15%"
        },
        // X轴 滑块 可缩放
        dataZoom: [
          {
            type: "slider",
            show: true,
            start: 0, // 开始百分数
            end: 100 // 结束百分数
          }
        ],
        xAxis: {
          type: "category",
          splitLine: {
            // X 轴分隔线样式
            show: true,
            lineStyle: {
              color: ["#f3f0f0"],
              width: 2,
              type: "solid"
            }
          },
          data: this.dataX
        },
        yAxis: [
          {
            name: "Y轴单位写的位置",
            type: "value",
            // max: 100,
            // min: 0,
            splitNumber: 10, // Y 轴分隔格数
            splitLine: {
              // Y 轴分隔线样式
              show: true,
              lineStyle: {
                color: ["#f3f0f0"],
                width: 2,
                type: "solid"
              }
            }
          }
        ],
        series: this.dataY
      };

      // 使用刚指定的配置项和数据显示图表。
      this.myChart.setOption(option);
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.dataX = this.list.map(item => item.x);
      this.dataY.push({
        name: "AA",
        type: "line",
        data: this.list.map(item => item.y)
      });

      this.init(this.dataX, this.dataY);
    });
  }
};
</script>

<style scoped>
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值