zoukankan      html  css  js  c++  java
  • Ant Design Vue 使用 ECharts(vue、Typescript)

    展示

      

    一、安装依赖

      npm install echarts --save

    二、全局引用

      import * as echarts from 'echarts'
      Vue.prototype.$echarts = echarts
    三、例VUE
    <template>
      <div id="myChart" style="height: 300px;  600px"></div>
    </template>
    
    <script>
    export default {
      name: "EChartsDemo",
      data() {
        return {
          msg: "ECharts Demo",
        };
      },
      mounted() {
        this.drawChart();
      },
      methods: {
        drawChart() {
          // 基于准备好的dom,初始化echarts实例
          let myChart = this.$echarts.init(document.getElementById("myChart"));
          // 指定图表的配置项和数据
          let option = {
            xAxis: {
              type: "category",
              data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            },
            yAxis: {
              type: "value",
            },
            series: [
              {
                data: [
                  120,
                  {
                    value: 200,
                    itemStyle: {
                      color: "#a90000",
                    },
                  },
                  150,
                  80,
                  70,
                  110,
                  130,
                ],
                type: "bar",
              },
            ],
          };
          // 使用刚指定的配置项和数据显示图表。
          myChart.setOption(option);
        },
      },
    };
    </script>

    四、例Typescript

    <template>
      <div :style="{ background: '#fff', padding: '24px', minHeight: '83vh' }">
        <div
          id="myChart1"
          style="
            height: 500px;
             800px;
            border: 1px solid red;
            display: inline-block;
          "
        ></div>
      </div>
    </template>
    <script lang="ts">
    import { Vue, Component, Prop } from "vue-property-decorator";
    
    @Component({
      components: {},
    })
    export default class Report extends Vue {
      mounted() {
        this.drawChart();
        this.$emit("selectMenu", 3);
      }
      drawChart() {
        // 基于准备好的dom,初始化echarts实例
        let myChart1 = (this as any).$echarts.init(
          document.getElementById("myChart1")
        );// 指定图表的配置项和数据
        let option1 = {
          title: {
            text: "Stacked Area Chart",
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "cross",
              label: {
                backgroundColor: "#6a7985",
              },
            },
          },
          legend: {
            data: ["Email", "Union Ads", "Video Ads", "Direct", "Search Engine"],
          },
          toolbox: {
            feature: {
              saveAsImage: {},
            },
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true,
          },
          xAxis: [
            {
              type: "category",
              boundaryGap: false,
              data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            },
          ],
          yAxis: [
            {
              type: "value",
            },
          ],
          series: [
            {
              name: "Email",
              type: "line",
              stack: "Total",
              areaStyle: {},
              emphasis: {
                focus: "series",
              },
              data: [120, 132, 101, 134, 90, 230, 210],
            },
            {
              name: "Union Ads",
              type: "line",
              stack: "Total",
              areaStyle: {},
              emphasis: {
                focus: "series",
              },
              data: [220, 182, 191, 234, 290, 330, 310],
            },
            {
              name: "Video Ads",
              type: "line",
              stack: "Total",
              areaStyle: {},
              emphasis: {
                focus: "series",
              },
              data: [150, 232, 201, 154, 190, 330, 410],
            },
            {
              name: "Direct",
              type: "line",
              stack: "Total",
              areaStyle: {},
              emphasis: {
                focus: "series",
              },
              data: [320, 332, 301, 334, 390, 330, 320],
            },
            {
              name: "Search Engine",
              type: "line",
              stack: "Total",
              label: {
                show: true,
                position: "top",
              },
              areaStyle: {},
              emphasis: {
                focus: "series",
              },
              data: [820, 932, 901, 934, 1290, 1330, 1320],
            },
          ],
        };// 使用刚指定的配置项和数据显示图表。
        myChart1.setOption(option1);
      }
    }
    </script>
  • 相关阅读:
    redhat 6.4重新安装python和yum
    【机器学习】置信区间上界算法UCB(Upper Confidence Bound)
    MAC终端zsh配置
    [Android] 重新打包(替换)签名APK
    UNI-APP常用方法
    一个请求的生命周期
    jquery追加元素的几种方法?(包括append()、prepend()、after()、before()、insertAfter()、insertBefore())
    怎样查外键建在哪个表上
    Redis实现分布式锁
    sql语句中对单个字段去重,distinct和group by性能分析
  • 原文地址:https://www.cnblogs.com/duhaoran/p/15775892.html
Copyright © 2011-2022 走看看