apexcharts数据可视化之饼图

apexcharts数据可视化之饼图

有完整配套的Python后端代码。

本教程主要会介绍如下图形绘制方式:

  • 基础饼图
  • 单色饼图
  • 图片饼图

基础饼图

jsx 复制代码
import ApexChart from 'react-apexcharts';

export function SimplePie() {
    // 数据序列
    const series = [44, 55, 13, 43, 22]
    // 图表选项
    const options = {
        chart: {
            width: 380,
            type: 'pie',
        },
        labels: ['Team A', 'Team B', 'Team C', 'Team D', 'Team E'],
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: 'bottom'
                }
            }
        }]
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="pie" height={550}/>
        </div>
    )
}

单色饼图

jsx 复制代码
import ApexChart from 'react-apexcharts';

export function MonochromePie() {
    // 数据序列
    const series = [25, 15, 44, 55, 41, 17]
    // 图表选项
    const options = {
        chart: {
            width: '100%',
            type: 'pie',
        },
        labels: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
        theme: {
            monochrome: {
                enabled: true
            }
        },
        plotOptions: {
            pie: {
                dataLabels: {
                    offset: -5
                }
            }
        },
        title: {
            text: "单色饼图"
        },
        dataLabels: {
            formatter(val, opts) {
                const name = opts.w.globals.labels[opts.seriesIndex]
                return [name, val.toFixed(1) + '%']
            }
        },
        legend: {
            show: false
        }
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="pie" height={550}/>
        </div>
    )
}

图片饼图

jsx 复制代码
import ApexChart from 'react-apexcharts';

export function ImagePie() {
    // 数据序列
    const series = [44, 33, 54, 45]
    // 图表选项
    const options = {
        chart: {
            width: 380,
            type: 'pie',
        },
        colors: ['#93C3EE', '#E5C6A0', '#669DB5', '#94A74A'],
        labels: ["星期一", "星期二", "星期三", "星期四"],
        // 使用图片填充
        fill: {
            type: 'image',
            opacity: 0.85,
            image: {
                src: ['/stripes.jpg', '/1101098.png', '/4679113782_ca13e2e6c0_z.jpg', '/2979121308_59539a3898_z.jpg'],
                width: 25,
                imagedHeight: 25
            },
        },
        stroke: {
            width: 4
        },
        dataLabels: {
            enabled: true,
            style: {
                colors: ['#111']
            },
            background: {
                enabled: true,
                foreColor: '#fff',
                borderWidth: 0
            }
        },
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: 'bottom'
                }
            }
        }]
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="pie" height={550}/>
        </div>
    )
}
相关推荐
天天扭码4 分钟前
不需要编写代码——借助Cursor零基础爬取微博热榜(含Cursor伪免费使用教程)
前端·openai·cursor
大阳光男孩5 分钟前
uniapp的通用页面及组件基本封装
前端·javascript·uni-app
Moment17 分钟前
跨端项目被改需求逼疯?FinClip 可能是非常不错的一次选择
前端·javascript
这里有鱼汤20 分钟前
无需HTML/CSS!用Python零基础打造专业级数据应用——Streamlit入门指南
前端·后端·python
Gazer_S23 分钟前
【行业树选择器组件:基于Vue3与Element Plus的高性能树形选择组件优化与重构】
前端·javascript·重构
白羊@38 分钟前
鸿蒙案例---生肖抽卡
前端·javascript·华为·harmonyos
橙某人44 分钟前
🍊🍊🍊在网格中进行拖动布局-Javascript、Vue
前端·javascript·vue.js
若川1 小时前
Taro 4 已发布:11. Taro 是如何解析入口配置 app.config.ts 和页面配置的?
前端·javascript·微信小程序
八了个戒1 小时前
「数据可视化 D3系列」入门第一章:Hello D3.js
开发语言·前端·javascript·数据可视化·canvas
二川bro1 小时前
深度解析 Vue 项目 Webpack 分包与合包 一文读懂
前端·vue.js·webpack