Vue3 使用ApexCharts图表

Vue3 使用ApexCharts图表

ApexCharts是我们常用的图表, Vue-ApexCharts 是 ApexCharts 的包装器组件。我们如何在Vue项目中使用呢?

安装

npm install --save apexcharts //标签
npm install --save vue3-apexcharts

配置

在main.js 中导入插件

import VueApexCharts from "vue3-apexcharts";

const app = createApp(App);
app.use(VueApexCharts);
// The app.use(VueApexCharts) will make <apexchart> component available everywhere.

使用

  • 条形图
<template>
 <apexchart width="500" type="bar" :options="barOptions" :series="barOptions.series"></apexchart>
 </template>
 
 <script setup>
  // 图标配置,更多配置可以看文档
  const barOptions = ref(null)
  const  barOptions = {
    //图标配置
    chart: {
      id'bar1',
    },
    //绘图选项
    plotOptions: {
      bar: {
        horizontaltrue//横向,默认竖直
      }
    },
    //数据标签
    dataLabels: {
      enabledfalse
    },
    // x轴
    xaxis: {
      categories: ['South Korea''Canada''United Kingdom''Netherlands''Italy''France''Japan''United States''China''Germany']
    },
     //颜色
    colors : ["#534686"],
    series: [{
      data: [400430448470540580690110012001380]
    }]
  }
 // 更新数据
 const updateChart = () => {
    const max = 90;
    const min = 20;
    const newData = barOptions.value.series[0].data.map(() => {
      return Math.floor(Math.random() * (max - min + 1)) + min
    })
    // In the same way, update the series option
    barOptions.value.series = [{
      data: newData
    }]

    console.log('barOptions.series',barOptions.value.series)
  }

</script>
Vue3 使用ApexCharts图表
image.png
  • 柱形图
<template>
 <apexchart width="500" type="bar" :options="columnOption" :series="columnOption.series"></apexchart>
 </template>
 <script setup>
 const columnOption = {
    chart: {
      id:'bar2',
      toolbar:{
        showfalse //不显示工具条
      }
    },
    plotOptions: {
      bar: {
        horizontalfalse,
        endingShape'rounded',
        columnWidth'55%',
      },
    },
    stroke: {
      showtrue,
      width2,
      colors: ['transparent']
    },
    //数据标签
    dataLabels: {
      enabledfalse
    },
    xaxis: {
      categories: ['Feb''Mar''Apr''May''Jun''Jul''Aug''Sep''Oct'],
    },
    series: [{
      name'Net Profit',
      data: [445557566158636066]
    }, {
      name'Revenue',
      data: [768510198871059111494]
    }, {
      name'Free Cash Flow',
      data: [354136264548525341]
    }],

    yaxis: {
      title: {
        text'$ (thousands)'
      }
    },
    fill: {
      opacity1

    },
    tooltip: {
      y: {
        formatterfunction (val{
          return "$ " + val + " thousands"
        }
      }
    },
    colors:[ '#534686' , '#f8d62b' , '#51bb25']
  }
  
</script>
Vue3 使用ApexCharts图表
image.png

更多效果:

Vue3 使用ApexCharts图表
image.png
Vue3 使用ApexCharts图表
image.png
Vue3 使用ApexCharts图表
image.png
Vue3 使用ApexCharts图表
image.png
Vue3 使用ApexCharts图表
image.png


原文始发于微信公众号(大前端编程教学):Vue3 使用ApexCharts图表

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/224203.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!