cytsunny
cytsunny

Reputation: 5030

How to make Y-axis of bar chart and line chart stick to left side for PHPExcel?

Currently when there are negative value in data, the y-axis of bar/line chart will be moved to middle of the graph by default. Is there a way to make the y-axis stick to the leftmost of the graph in PHPExcel?

Upvotes: 0

Views: 1690

Answers (1)

lthrhx
lthrhx

Reputation: 190

That can be done by setting the Y & X Axis styles. I don't recall which version implemented them so it may work with your current version, or grab the latest PHPExcel

PHPExcel_Chart_Axis is the new object that will be created. You can read more about it here and this is an example of it in action:

    $yAxisStyle =  new PHPExcel_Chart_Axis();
    $yAxisStyle->setAxisOptionsProperties('low', null, null, null, null, null, null, null, null, null); 

    $xAxisStyle =  new PHPExcel_Chart_Axis();
    $xAxisStyle->setAxisOptionsProperties('low', null, null, null, null, null, null, null, null, null); 

Each of those parameters are explained in the link above, but here is a cliff notes version:

        @param string $axis_labels                  'nextTo','low','high','none' (completely removes it altogether)
        @param string $horizontal_crosses_value     default=null (auto), numeric value 0-999
        @param string $horizontal_crosses           default=null,
        @param string $axis_orientation             default=null,
        @param string $major_tmt                    default=null, (major_tick_mark)
        @param string $minor_tmt                    default=null, (minor_tick_mark)
        @param string $minimum                      default=null,
        @param string $maximum                      default=null,
        @param string $major_unit                   default=null,
        @param string $minor_unit                   default=null,

Within your PHP file find the "new PHPExcel_Chart" section. Using the example below you can add in the Y and X axis styling:

    $chart= new PHPExcel_Chart(
                        'Chart1',       // name
                        $title,         // title displayed on chart
                        $legend,        // legend
                        $pa,            // plotArea
                        true,           // plotVisibleOnly
                        0,              // displayBlanksAs
                        NULL,           // xAxisLabel
                        $yAxisLabel,    // yAxisLabel
                        $xAxisStyle,    // X-axis styling vertical
                        $yAxisStyle,    //Y-axis style horizontal
                        null,
                        null
                    );

Upvotes: 1

Related Questions