koolphp / koolreport

This is an Open Source PHP Reporting Framework which you can use to write perfect data reports or to construct awesome dashboards using PHP
https://www.koolreport.com/
MIT License
228 stars 65 forks source link

GoogleChart: get type from column definition to support date string representation #27

Open mranner opened 5 years ago

mranner commented 5 years ago

You only take the label for the column defintion in Chart::prepareData(), so you cannot support date string representation for hAxis and therefore no trendlines.

With this patch, you will also respect the type definition from columns, allowing us to format datetime as date string representation, which is necessary for trendlines on datetime based datasets.

Index: vendor/koolphp/koolreport/src/widgets/google/Chart.php
===================================================================
--- vendor/koolphp/koolreport/src/widgets/google/Chart.php      (revision 4508)
+++ vendor/koolphp/koolreport/src/widgets/google/Chart.php      (working copy)
@@ -183,7 +183,11 @@
         $header = array();
         $columnExtraRoles = array("annotation", "annotationText", "certainty", "emphasis", "interval", "scope", "style", "tooltip");
         foreach ($columns as $cKey => $cSetting) {
-            array_push($header, "" . Utility::get($cSetting, "label", $cKey));
+                       $header_column = [ 'label' => "" . Utility::get($cSetting, "label", $cKey) ];
+                       if ($type = Utility::get($cSetting, "type", $cKey)) {
+                               $header_column['type'] = $type;
+                       }
+            array_push($header, $header_column);
             foreach ($columnExtraRoles as $cRole) {
                 if (isset($cSetting[$cRole])) {
                     array_push(
koolphp commented 5 years ago

Thank you very much!