2016-03-11 34 views
0

今天我正在與phpexcel合作在我的文件中生成一些條形圖。 關於我的傳說盡管如此,我不得到預期的標籤,除了第一:傳說圖表上奇怪的數據標籤

Bad labels on legend

我不明白,因爲我把正確的範圍,我dataseries標籤陣列。只有第一個標籤是正確的,但其他人都默認「系列2,Serie3,...」

這是我的代碼:

// Each worksheet 
foreach($tab_calcul as $calcul => $bool){ 

$tab_length_lig = ${"worksheet_$calcul"}->getHighestRow(); 
$tab_length_col = PHPExcel_Cell::columnIndexFromString(${"worksheet_$calcul"}->getHighestColumn())-1; 

/////////////////////////////////////////////////////////////////////// 
////////////////  DATASERIES BY SHOP  //////////////////////// 
/////////////////////////////////////////////////////////////////////// 

// Shop labels 
$dataseriesLabels = array(
    new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$A$4:$A$'.($tab_length_lig-1), NULL, $nb_enseigne) 
); 

// Dates 
$xAxisTickValues = array(
    new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$C$3:$'.ch2al($tab_length_col).'$3', NULL, $nb_synthese) 
); 

// Values 
$dataSeriesValues = array(); 
$cpt = 3; 

for($i = 0; $i < count($tab_enseigne); $i++) { 

    $cpt++; 
    array_push($dataSeriesValues, new PHPExcel_Chart_DataSeriesValues('Number', '$calcul!$C$'.$cpt.':$'.ch2al($tab_length_col).'$'.$cpt, NULL, $nb_synthese)); 
} 

// Build the dataseries 
$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_BARCHART,  // plotType 
    PHPExcel_Chart_DataSeries::GROUPING_STANDARD , // plotGrouping 
    range(0, count($dataSeriesValues)-1),   // plotOrder 
    $dataseriesLabels,        // plotLabel 
    $xAxisTickValues,        // plotCategory 
    $dataSeriesValues        // plotValues 
); 

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

/////////////////////////////////////////////////////////////////////// 
///////////////  DATASERIES ALL SHOPS  ///////////////////// 
/////////////////////////////////////////////////////////////////////// 

// Label all shops 
$dataseriesLabels2 = array(
    new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$A$'.($tab_length_lig), NULL, 1) 
); 

// Values 
$dataSeriesValues2 = array(
    new PHPExcel_Chart_DataSeriesValues('Number', '$calcul!$C$'.$tab_length_lig.':$'.ch2al($tab_length_col).'$'.$tab_length_lig, NULL, $nb_synthese) 
); 

// Build the dataseries 
$series2 = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_LINECHART,  // plotType 
    PHPExcel_Chart_DataSeries::GROUPING_STANDARD , // plotGrouping 
    range(0, count($dataSeriesValues2)-1),   // plotOrder 
    $dataseriesLabels2,        // plotLabel 
    $xAxisTickValues,        // plotCategory 
    $dataSeriesValues2        // plotValues 
); 

///////////////////////////////////////////////////////////////////////// 

// Set the series in the plot area 
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series, $series2)); 
// Set the chart legend 
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); 

$title = new PHPExcel_Chart_Title('Graphe '.$calcul." : ".utf8_encode($tab_data[$rmookid_periode]["marque"]." - ".$tab_data[$rmookid_periode]["modele"]." - ".$tab_data[$rmookid_periode]["ean"])); 

// Create the chart 
$chart = new PHPExcel_Chart(
    'chart1',  // name 
    $title,   // title 
    $legend,  // legend 
    $plotarea,  // plotArea 
    true,   // plotVisibleOnly 
    0,    // displayBlanksAs 
    NULL,   // xAxisLabel 
    NULL  // yAxisLabel 
); 

// Set the position where the chart should appear in the worksheet 
$chart->setTopLeftPosition('A17'); 
$chart->setBottomRightPosition('K30'); 

// Add the chart to the worksheet 
${"worksheet_$calcul"}->addChart($chart); 
} 

預先感謝您

回答

0

我固定它。這是一個巨大的錯誤,把$演算簡單報價:

'$calcul!$A$'.($tab_length_lig) 

應該是:

$calcul.'!$A$'.($tab_length_lig)