以下是使用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);
这是我在excel中得到的输出图表:
我希望Y轴垂直对齐,而不是水平对齐。任何帮助都会受到赞赏。
答案 0 :(得分:1)
然后尝试更改
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
到
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);
列是垂直的(从上到下),栏是水平的(从左到右)