首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PhpPresentation轴标签格式

PhpPresentation轴标签格式
EN

Stack Overflow用户
提问于 2021-05-24 21:14:59
回答 1查看 136关注 0票数 2

我正在尝试格式化y轴上的标签。

$axis->setFormatCode('#.0\%');

这不会提供任何更改,但我已经通过在writer类中添加getFormatCode();的回显来确认格式代码设置正确。

我已经测试过了,如果您更改了Writer\PowerPoint2007\PptCharts.php https://github.com/PHPOffice/PHPPresentation/blob/develop/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php#L2265,它将按预期工作

$objWriter->writeAttribute('sourceLinked', '0');

有人能告诉我为什么会这样吗?更重要的是,我如何让Y轴使用'%‘格式化数值标签?

编辑:添加代码

代码语言:javascript
复制
public function configure_axis($axis, $title='', $visible=true, 
$formatCode=null){
        
        $axis = strtolower($axis);
        
        // get the axis 
        switch($axis){
            case 'x':
            case 'categorical':
                $axis = $this->shape->getPlotArea()->getAxisX();
                break;
            case 'y':
                $axis = $this->shape->getPlotArea()->getAxisY();
                break;
            default:
                throw new Exception('Invalid axis');
        }
        
        $axis->setTitle($title);
        $axis->setIsVisible($visible);
        
        if(isset($formatCode)){
            $axis->setFormatCode($formatCode);
        }
        
    }
EN

回答 1

Stack Overflow用户

发布于 2021-06-22 04:11:36

你能展示一下你的代码,告诉我你使用的是哪个版本的PhpPresentation吗?

因为对我来说,下一个格式化setFormatCode('#.0\%')可以很好地工作。

下面是一个示例:

代码语言:javascript
复制
<?php

require_once 'vendor/autoload.php';

use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Chart\Series;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;

$seriesData = [
    'Monday' => 12,
    'Tuesday' => 15,
    'Wednesday' => 13,
    'Thursday' => 17,
    'Friday' => 14,
    'Saturday' => 9,
    'Sunday' => 7
];

$objPHPPowerPoint = new PhpPresentation();
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$areaChart = new Area();
$areaChart->addSeries(new Series('Downloads', $seriesData));

$shape = $currentSlide->createChartShape();
$shape->getTitle()->setVisible(false);
$shape->getLegend()->setVisible(false);
$shape->setResizeProportional(false)
    ->setWidth(800)
    ->setHeight(500)
    ->setOffsetX(50)
    ->setOffsetY(50);
$shape->getPlotArea()->setType($areaChart);

$shape->getPlotArea()->getAxisY()->setFormatCode('#.0\%');

$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . '/demo.pptx');

和结果:

下面是柱状图(PhpOffice\PhpPresentation\Shape\Chart\Type\Bar):的第二个结果

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67672701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档