在Vue3中使用echarts图表

第一步: 先安装echarts

npm install echarts --save

第二步:  在js中导入echarts

import * as echarts from "echarts";

第三步: 写出HTML样式,CSS样式

  <!-- echarts图表 -->
    <div class="echarts">
      <div id="echarts_con" />
    </div>
.echarts {
  margin: auto;
  border-radius: 8px;
  margin-top: 20px;
  width: 97%;
  background-color: white;
  height: 300px;
  #echarts_con {
    width: 100%;
    height: 100%;
  }
}

第四步: 在js中绑定HTML

const echarts_con = echarts.init(document.getElementById("echarts_con"));

第五步: 图表样式绘制

 echarts_con.setOption({
    title: {
      text: "近30天订单数量",
      left: 10,
      top: 10,
      textStyle: {
        //主标题文字样式
        color: "#505050", //字体颜色
        fontSize: 15, //字体大小
        // fontStyle:'italic',//斜体
        fontWeight: 500 //加粗
      }
    },
    grid: {
      left: "5%",
      right: "10%",
      top: "20%",
      bottom: "15%",
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: "axis"
    },
    xAxis: [
      {
        type: "category",
        axisLine: {
          show: true,
          lineStyle: {
            color: "#9a9a9a"
          }
        },
        axisTick: {
          show: true
        },
        axisLabel: {
          color: "#9a9a9a",
          margin: 6
        },
        splitLine: {
          show: false
        },
        boundaryGap: ["5%", "5%"],
        data: xData.value
      }
    ],
    yAxis: [
      {
        type: "value",

        axisLabel: {
          color: "#9a9a9a",
          margin: 6
        },
        splitLine: {
          lineStyle: {
            color: "#9a9a9a",
            type: "dashed"
          }
        }
      }
    ],
    series: [
      {
        name: "订单量",
        type: "line",
        stack: "总量",
        symbol: "circle",
        data: arr.value,
        symbolSize: 6,
        itemStyle: {
          color: "#3a8bef",
          borderColor: "#3a8bef",
          borderWidth: 2
        }
      }
    ]
  });

就这样一个echarts图表就完成了。最后可以根据自己的需要来修改内容绘制图表。

效果演示:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值