项目中使用echarts

Echarts版本:
在这里插入图片描述

  • echarts引入
import * as echarts from "echarts";

//k折线图
  simpleData().then((ok: any) => {
    console.log("折线图", ok);
    console.log(ok.data);

    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(
      document.getElementById("main") as HTMLDivElement
    );

    var option = {
      title: {
        text: "折线图",
        left: 'center',
        top: 20,
        textStyle: {
          color: "#f00",
        },
      },
      tooltip: {
        trigger: "axis",
      },
      xAxis: {
        type: "category",
        data: ok.data.map((item: any) => item.x),
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          data: ok.data.map((item: any) => item.val),
          type: "line",
          markPoint: {
            data: [
              {
                type: "max",
                name: "最大值",
              },
              {
                type: "min",
                name: "最小值",
              },
            ],
          },
        },
      ],
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  });	
  • 饼图
  // 饼图
  simpleData().then((ok: any) => {
    console.log("饼图", ok);
    console.log(ok.data);

    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(
      document.getElementById("two") as HTMLDivElement, 'dark'
    );
    let seriesData = reactive({
      arr: [],
    });
    ok.data.forEach((item: any) => {
      let obj = reactive({
        newobj: {},
      });
      obj.newobj = {
        name: item.x,
        value: item.val,
      };
      seriesData.arr.push(obj.newobj);
    });
    console.log(seriesData.arr);
    var option = {
      title: {
        text: "饼图",
        left: 'center',
        top: 20,
        textStyle: {
          color: "#f00",
        },
      },
      legend: {
        top: "bottom",
      },
      toolbox: {
        show: true,
        // feature: {
        //   mark: { show: true },
        //   dataView: { show: true, readOnly: false },
        //   restore: { show: true },
        //   saveAsImage: { show: true },
        // },
      },
      series: [
        {
          name: "Nightingale Chart",
          type: "pie",
          radius: [50, 250],
          center: ["50%", "50%"],
          roseType: "area",
          itemStyle: {
            borderRadius: 8,
            normal: {
              label: {
                show: true,
                formatter: "{b} : {c} ({d}%)",
              },
              labelLine: { show: true },
            },
          },
          data: seriesData.arr,
        },
      ],
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  });

二、多个请求发送
可以使用 promise

  //   prolist().then((ok) => {
  //     console.log(ok);
  //     arr.data = ok.data;
  //   });

  //   prolisttotal().then((ok)=>{
  //     console.log(ok.data.length);
  //     listnum.value = ok.data.length
  //   })

  Promise.all([prolist(), prolisttotal()]).then((ok) => {
    console.log(ok);
    arr.data = ok[0].data;
    listnum.value = ok[1].data.length;
  });

三、使用async修饰请求

// onMounted(()=>{
//     bannerlist().then((ok)=>{
//         console.log(ok);
//     })
// })
onMounted(async () => {
  let ok = await bannerlist();
  console.log(ok.data);
  arr.data = ok.data;
  console.log(arr.data);
});

四、删除操作

const handleDelete = (index: number, row: any) => {
  console.log(index, row.adminid);

  ElMessageBox.confirm("是否删除?", "删除", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      admindelete(row.adminid).then((ok:any) => {
        console.log(ok);
      });
    })
    .catch(() => {});
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值