Skip to content
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

Added the ability to enable gridlines and axislabels on charts #576

Merged
merged 3 commits into from
Mar 21, 2018

Conversation

FrankMeyer
Copy link
Contributor

Added options 'showAxisLabels', 'showGridX', 'showGridY' to charts style element.
Added appropriet set and get methods.
Those options can be testet in Sample_32_Charts.php, but they are set to false for now.
Default output of that sample is not changed.

FrankMeyer and others added 3 commits July 21, 2015 14:07
added options 'showAxisLabels', 'showGridX', 'showGridY' to charts style element
removed whitespace
changed inline if statement
@okrauth
Copy link

okrauth commented Mar 12, 2016

Any chance to add the function "Add Data Labels" to Pie charts?

@FrankMeyer
Copy link
Contributor Author

@okrauth: I`m not sure, for Pie Charts it is not working at the moment, maybe you can unpack a word doc with a Pie-Chart where the labels were created directly in Word. Then search for that labels in the xml files. Then you will see what you have to add to the PHPWord code to generate the correct XML Parts for PieChart labels. The Pie-Chart behaves somewhat different.

@betocantu93
Copy link

How to actually do this? Can't get it to work. any snippet?

@FrankMeyer
Copy link
Contributor Author

@betocantu93
see my changes in samples/Sample_32_Chart.php
or are you interested in the question of okrauth?

@betocantu93
Copy link

Im making several charts, like 300, so I need to label, use grids, and titles, I couldn't find a way to do it... Tried everything...
On Mar 30, 2016 11:36 AM, Frank Meyer [email protected] wrote:@betocantu93
see my changes in samples/Sample_32_Chart.php
or are you interested in the question of okrauth?

—You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub

@betocantu93
Copy link

Line charts only, I need to add some labels and a grid, with axis labels

@okrauth
Copy link

okrauth commented Mar 31, 2016

@FrankMeyer : I unpacked a docx did a comparison and noticed that in order to add a leyend to a pie chart one needs to add the following code to the xml chat.xml document:

<c:legend><c:legendPos val="r"/><c:layout/><c:overlay val="0"/></c:legend>

Not sure how to accomplish this (which document to edit in the php library... can you point me in the right direction? thanks

@FrankMeyer
Copy link
Contributor Author

@okrauth: The charts are contructed in the file PhpWord/Writer/Word2007/Part/Chart.php.
For the other chart types the labels were added to the axis, but in case of a PieChart there are no axis.
So I would gues that the legend must be added in the function writePlotArea(XMLWriter $xmlWriter) in Chart.php. Maybe you should have a look in which xml elements the <c:legend> element is embedded.

@okrauth
Copy link

okrauth commented Mar 31, 2016

@FrankMeyer Thank you. It looks like it is embedded at '<c:chart>'

'
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><c:date1904 val="0"/><c:lang val="en-US"/><c:roundedCorners val="1"/><mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"><mc:Choice Requires="c14" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart"><c14:style val="118"/>/mc:Choicemc:Fallback<c:style val="18"/>/mc:Fallback/mc:AlternateContent<c:chart><c:autoTitleDeleted val="1"/><c:plotArea><c:layout/><c:pieChart><c:varyColors val="1"/><c:ser><c:idx val="0"/><c:order val="0"/><c:cat><c:strLit><c:ptCount val="3"/><c:pt idx="0"><c:v>Yes/c:v/c:pt<c:pt idx="1"><c:v>No/c:v/c:pt<c:pt idx="2"><c:v>NA/c:v/c:pt/c:strLit/c:cat<c:val><c:numLit><c:formatCode>General/c:formatCode<c:ptCount val="3"/><c:pt idx="0"><c:v>1.0/c:v/c:pt<c:pt idx="1"><c:v>2.0/c:v/c:pt<c:pt idx="2"><c:v>1.0/c:v/c:pt/c:numLit/c:val/c:ser<c:dLbls><c:showLegendKey val="0"/><c:showVal val="0"/><c:showCatName val="0"/><c:showSerName val="0"/><c:showPercent val="0"/><c:showBubbleSize val="0"/><c:showLeaderLines val="1"/>/c:dLbls<c:firstSliceAng val="0"/>/c:pieChart/c:plotArea

<c:legend><c:legendPos val="r"/><c:layout/><c:overlay val="0"/>/c:legend

<c:plotVisOnly val="1"/><c:dispBlanksAs val="zero"/><c:showDLblsOverMax val="1"/>/c:chart<c:spPr><a:ln><a:noFill/>/a:ln/c:spPr/c:chartSpace'

@FrankMeyer
Copy link
Contributor Author

then you should add the legend part in this function: private function writeChart(XMLWriter $xmlWriter)
just after $this->writePlotArea($xmlWriter);

@okrauth
Copy link

okrauth commented Apr 1, 2016

@FrankMeyer will do... thanks

@phpdave
Copy link

phpdave commented Nov 1, 2016

I'm looking to add

Legend

  1. show legend at top

Axes

  1. Primary Horizontal Axis
    1.a show left to right axis
    2 Primary Vertical Axis
    2.b show default axis

Gridlines

  1. Primary Horizontal Gridlines
    1.a Major Gridlines
  2. Primary Vertical Gridlines
    2.a Minor Gridlines

Data Labels

  1. Above

Has this been implemented or because of the failed travis and scrutinzer checks it wasn't implemented?

@FrankMeyer
Copy link
Contributor Author

The checks have not run correctly at that time, I just don't have the permissions to rerun travis and scrutinizer. They may succeed.

@phpdave
Copy link

phpdave commented Jan 5, 2017

FYI I've added some comments on how to get data labels options and axis options to be outputted here #957

@scalco19
Copy link

scalco19 commented Mar 9, 2017

help add Show Value in Piechart

$xmlWriter->writeRaw(' <c:dLbl><c:extLst><c:ext><c:showVal val="1"/></c:ext></c:extLst></c:dLbl>');

I'm not successful

@diggamies
Copy link

@scalco19 You should read @phpdave 's thread #957 ! If you already read it try following in src/PhpWord/Writer/Word2007/Part/Chart.php in the writeSeries() method:

$xmlWriter->startElement('c:dLbls');
$xmlWriter->writeRaw('<c:showLegendKey val="0"/><c:dLblPos val="outEnd"/><c:showVal val="1"/><c:showCatName val="0"/><c:showSerName val="0"/><c:showPercent val="0"/><c:showBubbleSize val="0"/>');
$xmlWriter->endElement(); // </c:dLbls>

Works like a charm for me, but I am using $chartOptions as mentioned in #957

@troosan
Copy link
Contributor

troosan commented Mar 11, 2018

other features in #957

@troosan troosan merged commit a652847 into PHPOffice:develop Mar 21, 2018
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.

8 participants