我已经通过加载或读取php文件使用PHPExcel生成了图表栏。我已经成功地将数据写入其中,但是问题是将图表条数据图从行更改为列。这是excel文件。
这里是生成图表的代码。
<?php
$objWorksheet = $objPHPExcel->getActiveSheet();
$dataSeriesLabels = array( new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$C$8', NULL, 1), // Jan
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$D$8', NULL, 1), // Feb
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$E$8', NULL, 1), // Mar
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$F$8', NULL, 1), // Apr
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$G$8', NULL, 1), // Mei
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$H$8', NULL, 1), // Jun
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$I$8', NULL, 1), // Jul
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$J$8', NULL, 1), // Aug
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$K$8', NULL, 1), // Sep
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$L$8', NULL, 1), // Okt
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$M$8', NULL, 1), // Nov
new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$N$8', NULL, 1) // Des
);
$xAxisTickValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Responden!$B$9:$B$16', NULL, 8) // Questions
);
$dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$C$9:$C$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$D$9:$D$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$E$9:$E$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$F$9:$F$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$G$9:$G$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$H$9:$H$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$I$9:$I$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$J$9:$J$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$K$9:$K$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$L$9:$L$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$M$9:$M$16', NULL, 8),
new PHPExcel_Chart_DataSeriesValues('Number', 'Responden!$N$9:$N$16', NULL, 8)
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder //array(0,1)
$dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotArea = new PHPExcel_Chart_PlotArea($layout, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM, NULL, false);
$title = new PHPExcel_Chart_Title('GRAFIK TINGKAT KEPENTINGAN DAN KEPUASAN');
$xAxisLabel = NULL; //PHPExcel_Chart_Title('NilaiX');
$yAxisLabel = NULL; //new PHPExcel_Chart_Title('NilaiY');
// Create the chart
$chart = new PHPExcel_Chart(
'chart_measurement', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
$xAxisLabel, // xAxisLabel
$yAxisLabel // yAxisLabel
);
$chart->setTopLeftPosition('F7');
$chart->setBottomRightPosition('AB20');
$objWorksheet->addChart($chart);
?>
但是我想将图表更改为这样
the result should be looks like here或R2
在我看来,我称其为将数据图从行切换为列。非常感谢您的贡献。