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>
    )
}
相关推荐
Icoolkj5 分钟前
VuePress 与 VitePress 深度对比:特性、差异与选型指南
前端·javascript·vue.js
excel20 分钟前
CNN 分层详解:卷积、池化到全连接的作用与原理
前端
excel23 分钟前
CNN 多层设计详解:从边缘到高级特征的逐层学习
前端
西陵2 小时前
Nx带来极致的前端开发体验——任务编排
前端·javascript·架构
大前端helloworld2 小时前
从初中级如何迈入中高级-其实技术只是“入门卷”
前端·面试
东风西巷3 小时前
Balabolka:免费高效的文字转语音软件
前端·人工智能·学习·语音识别·软件需求
萌萌哒草头将军4 小时前
10个 ES2025 新特性速览!🚀🚀🚀
前端·javascript·vue.js
半夏陌离4 小时前
SQL 入门指南:排序与分页查询(ORDER BY 多字段排序、LIMIT 分页实战)
java·前端·数据库
whysqwhw4 小时前
鸿蒙工程版本与设备版本不匹配
前端