This is:
Insert a pie chart, but after the word is exported, the chart is blank.
I am a Chinese user, English is not good. Please forgive me.
do you have a sample code that I can run that will reproduce this?
@troosan
samples/Sample_32_Chart.php and test.php.
The code in the data using Chinese characters, to facilitate testing compatibility, you can replace it with English characters.
test.php:
<?php
namespace test;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\SimpleType\Jc;
require_once 'vendor/autoload.php';
$phpword = new PhpWord();
$phpword->addTitleStyle(1, ['name' => 'Microsoft YaHei', 'size' => 22], ['alignment' => Jc::CENTER]);
$section = $phpword->addSection();
$section->addTitle('This is a test document');
$section->addText('Document presentation generates a pie chart.', ['name' => '宋体', 'size' => 12]);
$categories = ['正面', '中性', '负面'];
$series = [6, 324, 47];
$chart = $section->addChart('pie', $categories, $series);
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
$phpword->save('test.docx', 'Word2007', true);
The data found in the chart is empty, open with Microsoft Word 2016.
can anyone help me?
did not have the time to look at it. But it seems Word 2016 does not like the way the data is stored.
Hi troosan,
I have a similar issue. The data in chart1.xml is incomplete, "c:v" elements have no value.
If I change Chart.php as follows it works:
$xmlWriter->startElement('c:v');
//$this->writeText($value);
$xmlWriter->text($value);
$xmlWriter->endElement(); // c:v
Also works with writeRaw(), so its not related to the isOutputEscapingEnabled setting. Any idea why this is happening? I'm using PHP 5.3.10.
Thanks!
@fedegar This fix also works for me on PHP 7.1.9
@fedegar
thanks for the fix, I've committed this change on the develop branch.
@fedegar I applied your suggested change in the /src/phpword/writter/word2007/Chart.php
What is the value of the $value you mentioned? After compiling the php code, it says undefined variable $value.
Thanks
@fedegar Never Mind, I was editing the wrong file...got it. Thanks
Also, could you tell me how to get the 'Data Labels' in the pie chart?
Most helpful comment
Hi troosan,
I have a similar issue. The data in chart1.xml is incomplete, "c:v" elements have no value.
If I change Chart.php as follows it works:
$xmlWriter->startElement('c:v');
//$this->writeText($value);
$xmlWriter->text($value);
$xmlWriter->endElement(); // c:v
Also works with writeRaw(), so its not related to the isOutputEscapingEnabled setting. Any idea why this is happening? I'm using PHP 5.3.10.
Thanks!