doubi4340 2019-05-01 11:48
浏览 36
已采纳

图表中时间值的数据系列值

I am create a report using PHPSpreadSheet, the data are time values base, and there is one chart to represent the monthly report, but the Chart Keep read my data as string , and the dataseriesvalues from PHPSpreadsheet only support DATASERIES_TYPE_STRING and DATASERIES_TYPE_NUMBER from PHPSpreadsheet Documention.

Edit : the time values are can be over 24 hours The expectations of the report are like this : enter image description here

But the reality the excel never show the chart, because the dataseriesvalues cannot read the time values.

My Code for chart only:

 $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条回答 默认 最新

  • dongtangu6889 2019-06-18 05:22
    关注

    So I'm able to fix this problem because of the dev hint on GitHub. Thx to MarkBaker for the hint.

    How To Fixed :

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

    and my error was wrong sheet name (before the sheet name's was 'Total' and now 'Monthly').

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!