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>
    )
}
相关推荐
Smile_Gently2 小时前
前端:最简单封装nmp插件(组件)过程。
前端·javascript·vue.js·elementui·vue
wyg_0311137 小时前
用deepseek学大模型04-模型可视化与数据可视化
人工智能·机器学习·信息可视化
luckycoke8 小时前
小程序立体轮播
前端·css·小程序
一 乐8 小时前
高校体育场管理系统系统|体育场管理系统小程序设计与实现(源码+数据库+文档)
前端·javascript·数据库·spring boot·高校体育馆系统
懒羊羊我小弟8 小时前
常用Webpack Loader汇总介绍
前端·webpack·node.js
祈澈菇凉9 小时前
ES6模块的异步加载是如何实现的?
前端·javascript·es6
我爱学习_zwj9 小时前
4.从零开始学会Vue--{{组件通信}}
前端·javascript·vue.js·笔记·前端框架
顾比魁9 小时前
XSS盲打:当攻击者“盲狙”管理员
前端·网络安全·xss
黑客老李9 小时前
新手小白如何挖掘cnvd通用漏洞之存储xss漏洞(利用xss钓鱼)
java·运维·服务器·前端·xss
晚风予星9 小时前
简记|LogicFlow自定义BPMN元素节点
前端