php - Chart not rendered properly -
i have small table
and want create type_donutchart
phpexcel library. took example code examples/33chartcreate-pie.php
file , adapted accordingly:
$dataserieslabels2 = array( //new phpexcel_chart_dataseriesvalues('string', 'summen!$a$1', null, 1), ); $xaxistickvalues2 = array( new phpexcel_chart_dataseriesvalues('string', 'summen!$b$1:$c$1', null, 2), ); $dataseriesvalues2 = array( new phpexcel_chart_dataseriesvalues('number', 'summen!$b$2:$c$2', null, 2), );
the file served script, when try open it, error message occurs:
we found problem content in "myfile.xlsx". want try recover as can? if trust source of workbook, click yes.
when click yes , activate editing on document, following message this:
excel has finished check , repair of file. parts of file have been repaired or discarded.
removed part: part /xl/drawings/drawing4.xml. (drawing form)
what's wrong in code? have modify?
notes:
- as can see, i'm using dataset in example. there's data in range
a1:c2
(see screenshot above). - the worksheets name
summen
, double checked, problem not typo of sheet. - it's been asked in comments, have tried removing comment
dataserieslabels2
entry.
my example
$objphpexcel = new phpexcel(); $objworksheet = $objphpexcel->getactivesheet(); $objworksheet->fromarray( array( array('whatever', 'cat1', 'cat2'), array(77, 247, 128), ) ); $objworksheet->settitle('summen'); $dataserieslabels1 = array( // new phpexcel_chart_dataseriesvalues('string', 'summen!$a$1', null, 1), ); $xaxistickvalues1 = array( new phpexcel_chart_dataseriesvalues('string', 'summen!$b$1:$c$1', null, 2), ); $dataseriesvalues1 = array( new phpexcel_chart_dataseriesvalues('number', 'summen!$b$2:$c$2', null, 2), ); $series1 = new phpexcel_chart_dataseries( phpexcel_chart_dataseries::type_donutchart, // plottype null, // plotgrouping range(0, count($dataseriesvalues1)-1), // plotorder $dataserieslabels1, // plotlabel $xaxistickvalues1, // plotcategory $dataseriesvalues1 // plotvalues ); $layout1 = new phpexcel_chart_layout(); $layout1->setshowval(true); $layout1->setshowpercent(true); $plotarea1 = new phpexcel_chart_plotarea($layout1, array($series1)); $legend1 = new phpexcel_chart_legend(phpexcel_chart_legend::position_right, null, false); $title1 = new phpexcel_chart_title('test pie chart'); $chart1 = new phpexcel_chart( 'chart1', // name $title1, // title $legend1, // legend $plotarea1, // plotarea true, // plotvisibleonly 0, // displayblanksas null, // xaxislabel null // yaxislabel - pie charts don't have y-axis ); // set position chart should appear in worksheet $chart1->settopleftposition('a7'); $chart1->setbottomrightposition('h20'); // add chart worksheet $objworksheet->addchart($chart1); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->setincludecharts(true); $objwriter->save(str_replace('.php', '.xlsx', __file__));
generates correctly without errors
Comments
Post a Comment