如何使用phpspreadsheets在折线图输出文件excel中设置线条颜色

时间:2019-05-10 09:51:38

标签: php linechart phpspreadsheet

■预期行为 ・通过折线图中的代码定制将折线图输出到带有彩色线条的excel文件中

■当前行为是什么? ・颜色线没有通过折线图中的代码进行自定义,但是示例代码不起作用

$dataSeriesLineLabels = [
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1, [], null, '008000'), // Temperature
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1, [], null, '0000FF'), // Rainfall
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1, [], null, '008000'), // Humidity
        ];

        $dataSeriesLineValues = [
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), // Temperature
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), // Rainfall
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), // Humidity
        ];

        // Build the dataseries
        $seriesLine = new DataSeries(
            DataSeries::TYPE_LINECHART, // plotType
            DataSeries::GROUPING_STACKED, // plotGrouping
            range(0, count($dataSeriesLineValues) - 1), // plotOrder
            $dataSeriesLineLabels, // plotLabel
            $xAxisTickValues, // plotCategory
            $dataSeriesLineValues, // plotValues
            null,
            null,
            DataSeries::STYLE_LINEMARKER
        );

        // Set the series in the plot area
        $plotArea = new PlotArea(null, [$seriesLine]);
        // Set the chart legend
        $legend = new Legend(Legend::POSITION_TOPRIGHT, null, false);
        $title = new Title('Average EndGame');
        // $xAxisLabel = new Title('Financial Period');
        // $yAxisLabel = new Title('Value ($k)');

        // Create the chart
        $chart = new Chart(
            'Average EndGame', // 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('B8');
        $chart->setBottomRightPosition('O25');

0 个答案:

没有答案