Search code examples
phpcodeigniterchartsphpexcelpchart

PHPExcel Chart Axis Options set Maximium


I have read this post PHPExcel Chart Axis Options set Minimum and my issue is like this, I want to set the max value (fixed) into the Axis, independently of values graphed.

I have read many posts, but I can not to get the answer to my problem.

The issue can be "Fixed" in Excel by going into the Axis format option and setting a Fixed value of max_value_scale (i.e. 20) for the max of that axis. Can I change this format options from within PHPExcel?

When I use pChart to render the chart (in another option provided by my system), I did this

$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>$max_value_scale+1));
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"LabelSkip"=>1,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_MANUAL,"ManualScale"=>$AxisBoundaries,"MinDivHeight"=>50);

I render this image: rendered

but I need something like this:needed


My chart is created normally, I have been verifying a lot of posts and forums, but I can't find the solution to this issue.

$chart = new PHPExcel_Chart(
    'chart1',       // name
    $title,         // title
    $legend,        // legend
    $plotarea,      // plotArea
    true,           // plotVisibleOnly
    0,              // displayBlanksAs
    $xAxisLabel,    // xAxisLabel
    $yAxisLabel     // yAxisLabel
);

Solution

  • There was a bug in PHPExcel which is fixed by this commit of mine: https://github.com/PHPOffice/PHPExcel/commit/1a237573f9127a02388f4e306732122b39d1ea49

    Usage example (100 is the max. value):

    $axis =  new PHPExcel_Chart_Axis();
    $axis->setAxisOptionsProperties('nextTo', null, null, null, null, null, null, 100);
    
    $chart = new PHPExcel_Chart('chart' . $locTL, $title, $legend, $pa, true, 0, NULL, NULL, $axis);
    

    Install the version of PHPExcel which has this bug fix or apply the patch on top of your version.