amit_183
amit_183

Reputation: 981

changing alignment of Y-Axis in PHPEXCEL

Following is my code to generate the Chart using PHPEXCEL:

$categories = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C'.$old_constant.':$C'.$new_constant);
        $values = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E'.$old_constant.':$E'.$new_constant);
        $series = new PHPExcel_Chart_DataSeries(
            PHPExcel_Chart_DataSeries::TYPE_BARCHART,       // plotType
            PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED,  // plotGrouping
            array(0),                                       // plotOrder
            array(),                                        // plotLabel
            array($categories),                             // plotCategory
            array($values)                                  // plotValues
          );
        $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

        $layout = new PHPExcel_Chart_Layout();
        $plotarea = new PHPExcel_Chart_PlotArea($layout, array($series));
        $title = new PHPExcel_Chart_Title($row[meter_name]);
        $yAxisLabel = new PHPExcel_Chart_Title('Energy Consumed (KWH)');
        $xAxisLabel = new PHPExcel_Chart_Title('Day');

        $chart = new PHPExcel_Chart('sample', $title, null, $plotarea,true,0,$xAxisLabel,$yAxisLabel);


        $chart->setTopLeftPosition('M'.$old_constant);

        $chart->setBottomRightPosition('Z'.($new_constant+5));


        $constant=$constant+5;
        $objPHPExcel->getActiveSheet()->addChart($chart);

And this is the output chart which i get in the excel: enter image description here

I want the Y-axis to be aligned vertically,not horizontally.Any help would be appreciated.

Upvotes: 1

Views: 1413

Answers (1)

Mark Baker
Mark Baker

Reputation: 212452

Then try changing

$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

to

$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);

Columns are vertical (top to bottom), Bars are horizontal (left to right)

Upvotes: 1

Related Questions