React18 apexcharts数据可视化之甜甜圈图

36 篇文章 0 订阅

03 甜甜圈图

apexcharts数据可视化之甜甜圈图。

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

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

  • 基本甜甜圈图
  • 个性图案的甜甜圈图
  • 渐变色的甜甜圈图

面包圈

import ApexChart from 'react-apexcharts';

export function DonutUpdate() {
    // 数据序列
    const series = [44, 55, 13, 33]
    // 图表选项
    const options = {
        // 图表
        chart: {
            width: 380,
            type: 'donut',
        },
        dataLabels: {
            enabled: false
        },
        // 响应式
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    show: false
                }
            }
        }],
        // 图例
        legend: {
            position: 'right',
            offsetY: 0,
            height: 230,
        }
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="donut" height={600}/>
        </div>
    )
}

在这里插入图片描述

个性图案

import ApexChart from 'react-apexcharts';

export function DonutWithPattern() {
    // 数据序列
    const series = [44, 55, 41, 17, 15]
    // 图表选项
    const options = {
        // 图表选项
        chart: {
            width: 380,
            type: 'donut',
            // 阴影
            dropShadow: {
                enabled: true,
                color: '#111',
                top: -1,
                left: 3,
                blur: 3,
                opacity: 0.2
            }
        },
        stroke: {
            width: 0,
        },
        // 绘图选项
        plotOptions: {
            pie: {
                donut: {
                    labels: {
                        show: true,
                        total: {
                            showAlways: true,
                            show: true
                        }
                    }
                }
            }
        },
        labels: ["喜剧片", "动作片", "科幻片", "戏剧片", "恐怖片"],
        dataLabels: {
            dropShadow: {
                blur: 3,
                opacity: 0.8
            }
        },
        // 填充样式
        fill: {
            type: 'pattern',
            opacity: 1,
            pattern: {
                enabled: true,
                style: ['verticalLines', 'squares', 'horizontalLines', 'circles', 'slantedLines'],
            },
        },
        states: {
            hover: {
                filter: 'none'
            }
        },
        // 主题
        theme: {
            palette: 'palette2'
        },
        // 标题
        title: {
            text: "最喜欢的电影类型统计图"
        },
        // 响应式
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: 'bottom'
                }
            }
        }]
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="donut" height={600}/>
        </div>
    )
}

在这里插入图片描述

渐变

import ApexChart from 'react-apexcharts';

export function DonutGradient() {
    // 数据序列
    const series = [44, 55, 41, 17, 15]
    // 图表选项
    const options = {
        chart: {
            width: 380,
            type: 'donut',
        },
        // 绘制选项:自定义开始角度和结束角度
        plotOptions: {
            pie: {
                startAngle: -90,
                endAngle: 270
            }
        },
        dataLabels: {
            enabled: false
        },
        labels: ["喜剧片", "动作片", "科幻片", "戏剧片", "恐怖片"],
        // 填充类型:渐变
        fill: {
            type: 'gradient',
        },
        legend: {
            formatter: function(val, opts) {
                return val + " - " + opts.w.globals.series[opts.seriesIndex]
            }
        },
        title: {
            text: '渐变甜甜圈与自定义的开始角度'
        },
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: 'bottom'
                }
            }
        }]
    }
    return (
        <div id="chart">
            <ApexChart options={options} series={series} type="donut" height={550}/>
        </div>
    )
}

在这里插入图片描述

  • 11
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Python私教

创业不易,请打赏支持我一点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值