3

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
);
Community
  • 1
  • 1
Angel Doza
  • 1,096
  • 1
  • 18
  • 34

2 Answers2

3

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.

user38759
  • 96
  • 1
  • 3
  • Thanks you so much, I hadn't a server where I could do my proofs until today. It works! – Angel Doza Jul 24 '16 at 02:15
  • This sadly didn't work for me despite multiple efforts, though it seems to have worked for a few others. Perhaps I need to double-check my PHPExcel version or something. – joeljpa Aug 18 '23 at 06:54
1

Like the StackOverflow question you linked to mentions, PHPExcel (as of 1.8.1) is unable to programmatically change the y-axis chart scale. The y-axis chart scale is automatically generated from the chart's data, and you have no control over this.

pChart and PHPExcel are separate libraries. Unfortunately, the configuration to adjust the scale, available in pChart, is not available in PHPExcel. So, using PHPExcel, you cannot auto-generate charts that configure the y-axis as you are asking for.

If you are set on including a chart-image with a customized maximum/minimum y-axis scale, you could render your pChart images, then insert those images into a Worksheet via PHPExcel. The obvious downside is that the user of your final spreadsheet document will be unable to configure the chart-images on their own (since they would be images, not charts).

Community
  • 1
  • 1
Dave Mulder
  • 116
  • 1
  • 6