ECharts 图形化看板 模板(简单实用)

目录

一、官网

二、模板

①定义请求​编辑

②  将请求统一管理,别的页面引用多个请求时更便于导入。​编辑

③最终模板 

 三、执行效果

四、后端代码

4.1 controller

4.2 xml

4.3 测试接口


一、官网

获取 ECharts - 入门篇 - 使用手册 - Apache ECharts

二、模板

自己封装了一下 比原有的功能增强了一些(可以折线图和柱状体互相转化)

①定义请求

import http from "@/http/index";
export default {
  select: {
    name: "商品展示",
    url: "/api/select",
    call: async function name(params: any = {}) {
      return await http.get(this.url, params);
    },
  },
  
};

②  将请求统一管理,别的页面引用多个请求时更便于导入。

③最终模板 

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

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
import { productApi } from "@/api/index";

onMounted(() => {
  productApi.select.call().then((res: any) => {
    console.log(res);

    initCharts(res);
  });
});

const initCharts = (res: any) => {
  let option = {
    title: {
      text: "商品展示图",
    },
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "cross",
        crossStyle: {
          color: "#999",
        },
      },
    },
    toolbox: {
      show: true,
      feature: {
        dataZoom: {
          yAxisIndex: "none",
        },
        dataView: { readOnly: false },
        magicType: { type: ["line", "bar"] },
        restore: {},
        saveAsImage: {},
      },
    },
    xAxis: {
      type: "category",
      name:"商品名称",
      axisLabel: {
        interval: 0, // 强制显示所有标签
        rotate: 0, // 旋转角度,根据实际情况调整
      },
      data: res.map((obj: any) => obj.name),
    },
    yAxis: {
      name: "商品价格",
      type: "value",
    },
    series: [
      {
        name: "inventory",
        data: res.map((obj: any) => obj.price),
        type: "bar",
        tooltip: {
          valueFormatter: function (value: any) {
            return value + " 中国";
          },
        },
      },
    ],
  };

  // 基于准备好的dom,初始化echarts实例
  var myChart = echarts.init(document.getElementById("main"));
  // 绘制图表
  myChart.setOption(option);

  window.onresize = function () {
    myChart.resize();
  };
};
</script>

 三、执行效果

四、后端代码

4.1 controller

 

4.2 xml

 

4.3 测试接口

 

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-08 17:04:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-08 17:04:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-08 17:04:04       87 阅读
  4. Python语言-面向对象

    2024-06-08 17:04:04       96 阅读

热门阅读

  1. 开关电源中电感设计

    2024-06-08 17:04:04       35 阅读
  2. 自注意力机学习

    2024-06-08 17:04:04       30 阅读
  3. 本地文件传远程开发

    2024-06-08 17:04:04       22 阅读
  4. 2024年公路安全员考试题库

    2024-06-08 17:04:04       28 阅读
  5. 03-3.3.2_1 栈在表达式求值中的应用(上)

    2024-06-08 17:04:04       29 阅读
  6. 医疗实施-项目管理04-需求调研

    2024-06-08 17:04:04       31 阅读
  7. c#通过sqlsugar查询信息并日期排序

    2024-06-08 17:04:04       31 阅读