Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Horizontal Stacked Barchart

$
0
0

Sure:

$series = array();
for ($r = 11; $r <= 16; $r++)
{
    $label = new PHPExcel_Chart_DataSeriesValues('String', 'A'.$r,null,1);
    $value = new PHPExcel_Chart_DataSeriesValues('Number', 'D'.$r,null,1);
    $series[count($series)] = new PHPExcel_Chart_DataSeries( PHPExcel_Chart_DataSeries::TYPE_BARCHART      
                                                           , PHPExcel_Chart_DataSeries::GROUPING_STACKED   
                                                           , array(0)                                      
                                                           , array($label)                                 
                                                           , null                                          
                                                           , array($value)                                 
                                                           );
    $series[count($series)-1]->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);
}

$label = new PHPExcel_Chart_DataSeriesValues('String', 'A4',null,1);
$value = new PHPExcel_Chart_DataSeriesValues('Number', 'G4',null,1);
$series[count($series)] = new PHPExcel_Chart_DataSeries( PHPExcel_Chart_DataSeries::TYPE_BARCHART        
                                                        , PHPExcel_Chart_DataSeries::GROUPING_STACKED    
                                                        , array(0)                                       
                                                        , array($label)                                 
                                                        , null                                          
                                                        , array($value)                                  
                                                        );
$series[count($series)-1]->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);


$layout = new PHPExcel_Chart_Layout();
$plotarea = new PHPExcel_Chart_PlotArea($layout,  $series) ;

$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);
$chart = new PHPExcel_Chart( $title
                           , null
                           , $legend
                           , $plotarea
                           , true
                           , 0
                           , null
                           , null
                           );
$chart->setTopLeftPosition('A'.($mr+2));
$chart->setBottomRightPosition('K'.($mr+22));
$sheet->addChart($chart);


Here's a screenshot of the result: http://user.math.uzh.ch/berner/files/bar_graph.png 

 

 

Thanks.

 

mfg Tobias


Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>