PHPExcel-Xaxis值未显示在散点图上

时间:2019-09-18 08:41:04

标签: php excel phpexcel excel-charts

我正在尝试显示通过PHPExcel-1.8生成的Scatter(XY)图表。但是,它没有显示x轴值。

Here is my Code:

$ea = new PHPExcel();
    $ews = $ea->getSheet(0);
    $ews->setTitle('Data');
    $ews->fromArray($data[0]['data'], ' ','B1');
    $count = count($data[0]['data']);
    $xAxis_Values = 'Data!$B$2:$B$' . $count;
    $xal = array(
        new \PHPExcel_Chart_DataSeriesValues('String', $xAxis_Values , null, $count-1)
    );
    $dsl = array(
        new \PHPExcel_Chart_DataSeriesValues('String', strval('Data!$C$1:$C$' . $count), null, $count-1)
    );
    $dataseriesLabels = array(new PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$1'));
    //      Build the dataseries
    $ds = new PHPExcel_Chart_DataSeries(
        PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART,          // plotType
        null,    // plotGrouping
        array(0),                                  // plotOrder
        $dataseriesLabels,                                         // plotLabel
        $xal,                                                    // plotCategory
        $dsl,
        null,
        null,
        PHPExcel_Chart_DataSeries::STYLE_SMOOTHMARKER
    );
     $xAxisStyle =  new PHPExcel_Chart_Axis();
     $xAxisStyle->setAxisOptionsProperties('low', null, null, null, null, null, null, null, null, null); 
     $yAxisStyle =  new PHPExcel_Chart_Axis();
     $yAxisStyle->setAxisOptionsProperties('low', null, null, null, null, null, null, null, null, null); 
    $layout = new PHPExcel_Chart_Layout();
    $pa = new PHPExcel_Chart_PlotArea($layout, array($ds));
    $legend = new PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_TOP, NULL, false);
    $title = new \PHPExcel_Chart_Title('xy chart');
    $chart =   new PHPExcel_Chart(
        'Chart',
        $title,
        $legend,
        $pa,
        true,
        0,
        null,
        null,
        $xAxisStyle,
        $yAxisStyle
         );
    $chart->setTopLeftPosition('K1');
    $chart->setBottomRightPosition('T20');
    $ews->addChart($chart);

输出:

enter image description here

图表中缺少

x轴标签。以下是我给定的数据系列。

enter image description here

我的输出excel文件。

0 个答案:

没有答案