DataSeriesValues ​​для значений времени в символах - PullRequest
0 голосов
/ 01 мая 2019

Я создаю отчет с использованием PHPSpreadSheet, данные представляют собой базу значений времени, и существует один график для представления ежемесячного отчета, но Chart Keep считывает мои данные в виде строки, а dataseriesvalues из PHPSpreadsheet поддерживает только DATASERIES_TYPE_STRING и DATASERIES_TYPE_NUMBER из Документация по электронной таблице PHPS .

Редактировать : значения времени могут превышать 24 часа. Ожидания отчета следующие: enter image description here

Но в действительности Excel никогда не показывает диаграмму, потому что значения данных не могут считывать значения времени.

Мой код только для диаграммы:

 $dataSeriesLabels1 = [
                new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Monthly!$H$5', null, 1), // Pencapaian
            ];
            $dataSeriesLabels2 = [
                new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Monthly!$C$4', null, 1), // Target
            ];
            $xAxisTickValues = [
                new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Monthly!$B$6:$B$'.($countdata1+5), null, $countdata1), // Jan to Dec
            ];
            $dataSeriesValues1 = [
                new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Monthly!$H$6:$H$'.($countdata1+5), null, $countdata1),
            ];

            // Build the dataseries
            $series1 = new DataSeries(
                DataSeries::TYPE_BARCHART,//plotType
                DataSeries::GROUPING_CLUSTERED,//plotGrouping
                range(0, count($dataSeriesValues1) - 1),//plotOrder
                $dataSeriesLabels1,//plotLabel
                $xAxisTickValues,//plotCategory
                $dataSeriesValues1//plotValues
            );
            $series1->setPlotDirection(DataSeries::DIRECTION_COL);
            $dataSeriesValues2 = [
                new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,'Total!$C$6:$C$'.($countdata1+5), null, $countdata1),
            ];
            // Build the dataseries
            $series2 = new DataSeries(
                DataSeries::TYPE_LINECHART, // plotType
                DataSeries::GROUPING_STANDARD, // plotGrouping
                range(0, count($dataSeriesValues2) - 1), // plotOrder
                $dataSeriesLabels2, // plotLabel
                [], // plotCategory
                $dataSeriesValues2// plotValues
            );
            $plotArea = new PlotArea(null, [$series1, $series2]);
            // Set the chart legend
            $legend = new Legend(Legend::POSITION_RIGHT, null, false);
            $title = new Title('Lost Time '.$test);
            $yAxisLabel = new Title('Time');
            $xAxisLabel= new Title('Month');
            // Create the chart
            $chart = new Chart(
                'chart1', // name
                $title, // title
                $legend, // legend
                $plotArea, // plotArea
                true, // plotVisibleOnly
                0, // displayBlanksAs
                $xAxisLabel, // xAxisLabel
                $yAxisLabel  // yAxisLabel
            );
            // Set the position where the chart should appear in the worksheet
            $chart->setTopLeftPosition('K3');
            $chart->setBottomRightPosition('W25');
            $oke->addChart($chart);

1 Ответ

0 голосов
/ 18 июня 2019

Так что я могу решить эту проблему из-за подсказки разработчиков на GitHub. Спасибо MarkBaker за подсказку.

Как исправить:

$dataSeriesValues = [new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, '{Range of Cells for Values}','{setFormatType (e.g. [h]:mm:ss)}',{data count}),];

и моей ошибкой было неправильное имя листа (раньше имя листа было «Всего», а теперь «Ежемесячно»).

...