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').

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

报告相同问题?

悬赏问题

  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错