2014-07-03 167 views
1

我试图在通过PHPExcel生成的图表上显示X轴标签。但它只给我默认名称(1,2,3和Series1)而不是真实的标签。PHPExcel:显示图表X轴标签

这里是我使用的代码:

 $xlsSheet->fromArray($exportAnswers, null, 'A1'); 

     $dataseriesLabels = array(
      new PHPExcel_Chart_DataSeriesValues('String', '!$A$2:$A$4', NULL, 3) 
     ); 

     $xAxisTickValues = array(
      new PHPExcel_Chart_DataSeriesValues('String', '!$A$2:$A$4', NULL, 3) 
     ); 

     $dataSeriesValues = array(
      new PHPExcel_Chart_DataSeriesValues('Number', '!$B$2:$B$4', NULL, 3) 
     ); 

     $series = new PHPExcel_Chart_DataSeries(
      PHPExcel_Chart_DataSeries::TYPE_BARCHART,  // plotType 
      NULL,           // plotGrouping 
      range(0, count($dataSeriesValues) - 1),   // plotOrder 
      $dataseriesLabels,        // plotLabel 
      $xAxisTickValues,        // plotCategory 
      $dataSeriesValues,        // plotValues 
      NULL 
     ); 
     $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); 

     $plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series)); 
     $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); 
     $title = new PHPExcel_Chart_Title($b['block_title']); 

     $chart = new PHPExcel_Chart(
      $b['block_title'],  // name 
      $title,     // title 
      $legend,    // legend 
      $plotarea,  // plotArea 
      true,   // plotVisibleOnly 
      0,    // displayBlanksAs 
      NULL,   // xAxisLabel 
      NULL   // yAxisLabel 
     ); 

     $chart->setTopLeftPosition('H2'); 
     $chart->setBottomRightPosition('P20'); 
     $xlsSheet->addChart($chart); 

这里是结果在Excel中:

Result in Excel

非常感谢您的帮助!

回答

2

尝试删除从'!$A$2:$A$4'!或包括实际的工作表名称前!

+0

谢谢SOOOO了! :) – mAydie