gpt4 book ai didi

perl - Spreadsheet::WriteExcel (perl) 中饼图的更多格式

转载 作者:行者123 更新时间:2023-12-04 20:47:47 26 4
gpt4 key购买 nike

有谁知道是否可以向饼图添加更多格式?例如,在图表本身上显示每个切片的百分比,还是在旁边/上显示每个切片的标签?而不是只有一个简单的传说?

谢谢!

最佳答案

Spreadsheet::WriteExcel 是不可能的但是Excel::Writer::XLSX 是可能的.

这是一个例子:

#!/usr/bin/perl

use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( 'chart_pie.xlsx' );
my $worksheet = $workbook->add_worksheet();
my $bold = $workbook->add_format( bold => 1 );

# Add the worksheet data that the charts will refer to.
my $headings = [ 'Category', 'Values' ];
my $data = [
[ 'Apple', 'Cherry', 'Pecan' ],
[ 60, 30, 10 ],
];

$worksheet->write( 'A1', $headings, $bold );
$worksheet->write( 'A2', $data );

# Create a new chart object. In this case an embedded chart.
my $chart = $workbook->add_chart( type => 'pie', embedded => 1 );

# Configure the series.
$chart->add_series(
name => 'Pie sales data',
categories => [ 'Sheet1', 1, 3, 0, 0 ],
values => [ 'Sheet1', 1, 3, 1, 1 ],
data_labels => { value => 1 },
);

# Add a title.
$chart->set_title( name => 'Popular Pie Types' );

# Set an Excel chart style. Colors with white outline and shadow.
$chart->set_style( 10 );

# Insert the chart into the worksheet (with an offset).
$worksheet->insert_chart( 'C2', $chart, 25, 10 );

__END__

这是它显示的图表:
enter image description here

关于perl - Spreadsheet::WriteExcel (perl) 中饼图的更多格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6117526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com