Skip to content

Added setFirstSliceAngle to Doughnut Chart #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

seanlynchwv
Copy link

@seanlynchwv seanlynchwv commented Jul 10, 2025

Description

We needed the ability to create a half circle from 270' to 90' but it was not working

This is now fixed by adding a new ->setFirstSliceAngle( int ); helper to Doughnut.php

Previously this was hard-coded to 0. Over-writing this did not work as <c:view3D> was imported into every chart which was conflicting with the rule.

After debugging the output from powerpoint itself, I learned that we can fix this by making <c:view3D> conditional. Now making programatic changes to 2d charts works as expected.

It now works:

            $real = [15, 25, 30, 20, 10];
            $dummy = array_sum($real);
            $values = array_merge([$dummy], $real);

            $doughnut = (new Doughnut())
                ->setHoleSize(75)
                ->setFirstSliceAngle(90);

            $series = new Series('Gauge', $values);
            $series->setShowValue(false);
            $doughnut->addSeries($series);

            /* make the dummy slice transparent */
            $series->getDataPointFill(0)
                ->setFillType(Fill::FILL_SOLID)
                ->setStartColor(new Color('00FFFFFF'));

            $chart = $slide->createChartShape()
                ->setName('Gauge')
                ->setResizeProportional(false)
                ->setOffsetX($offsetX)
                ->setOffsetY($offsetY)
                ->setWidth($w)
                ->setHeight($h);

            $chart->getPlotArea()->setType($doughnut);
            $chart->getLegend()->setVisible(false);
            $chart->getTitle()->setVisible(false);
Screenshot 2025-07-11 at 14 43 54

Fixes # (issue)

Checklist:

  • My CI is 🟢
  • I have covered by unit tests my new code (check build/coverage for coverage report)
  • [o] I have updated the documentation to describe the changes - not yet, its still TODO
  • I have updated the changelog - not yet

@auto-assign auto-assign bot requested a review from Progi1984 July 10, 2025 10:56
@seanlynchwv
Copy link
Author

Sorry did not mean to create a PR here which happened automatically when I created a PR on my copy of the repo. Will try to submit a PR later if I can get the doughnut rotation working as expected

@seanlynchwv seanlynchwv reopened this Jul 11, 2025
@seanlynchwv seanlynchwv changed the title Add rotation Added setFirstSliceAngle to Doughnut Chart Jul 11, 2025
@coveralls
Copy link

coveralls commented Jul 11, 2025

Coverage Status

coverage: 91.643% (+0.004%) from 91.639%
when pulling deaec5e on seanlynchwv:feature/angle-rotation
into b9cdcd4 on PHPOffice:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants