《图解Echarts in Vue》Line实例- Basic

2021-06-08  本文已影响0人  张中华
result

code:

<template>
  <div class="chart" style="height: 300px; width: 800px;"></div>
</template>

<script>
export default {
  methods: {
    initChart() {
      const dom = document.querySelector(".chart");
      const chart = this.$echarts.init(dom);
      const option = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [150, 230, 224, 218, 135, 147, 260],
            type: "line",
          },
        ],
      };
      chart.setOption(option);
    },
  },
  mounted() {
      this.initChart();
  },
};
</script>

创建步骤

知识点: xAxis.type

这里讲下xAxis的type的使用,xAxis组件是直角坐标系 X 轴,这个组件里面有很多属性, 它里面有个type的属性,xAxis.type = 'category'
它代表坐标轴类型。
可选:

有时我们希望线能平滑一些,而不是折线,这时只需要在series里面添加smooth: true即可。


代码:
上一篇 下一篇

猜你喜欢

热点阅读