/** * Outputs the chart javascript into the page * * Pass in a string of the html elementID that you want the chart to be * rendered into. Plus, if the dataTable function was never called on the * chart to assign a DataTable to use, it will automatically attempt to use * a DataTable with the same label as the chart. * * @param string $elementID * @return string Javscript code blocks */ public function outputInto($elementID = NULL) { if ($this->dataTable === NULL) { $this->dataTable = $this->chartLabel; } if (gettype($elementID) == 'string' && $elementID != NULL) { $this->elementID = $elementID; } return Gcharts::_build_script_block($this); }
public function width($width) { if (is_int($width)) { $this->addOption(array('width' => $width)); return $this; } else { Gcharts::_set_error(get_class($this), 'Invalid width, must be (int)'); } }
/** * Adds the error message to the error log in the gcharts master object. * * @param string $msg error message. */ private function error($msg) { Gcharts::_set_error(get_class($this), $msg); }
private function getReportCharts($reportObj, $export_pdf_format, $currency_id = "") { global $log; $log->debug("Entering ./modules/ITS4YouReports/GenerateObj.php::getReportCharts"); global $log; $log->debug("Entering ./modules/ITS4YouReports/GenerateObj.php::getReportCharts"); global $log; $log->debug("Entering ./modules/ITS4YouReports/GenerateObj.php::getReportCharts"); global $log; $log->debug("Entering ./modules/ITS4YouReports/GenerateObj.php::getReportCharts"); $report_html = ""; $is_stacked = false; global $current_user; global $default_charset; $filename = "R4YouCharts"; if (isset($current_user) && $current_user->id != "") { $filename .= "_" . $current_user->id; } $reportid = $this->report_obj->record; $filename .= "_" . $reportid; $ch_data = ""; $dataseries = array(); if (isset($this->ch_array) && $this->ch_array["charttype"] != "none" && !empty($this->ch_array["dataseries"])) { $charttype = $this->ch_array["charttype"]; $charttitle = html_entity_decode($this->ch_array["charttitle"], ENT_QUOTES, $default_charset); if ($charttype == "funnel") { $chart_lbl_key = $this->ch_array["dataseries_label"]["val"]; $chart_lbl_val = $this->ch_array["dataseries_label"]["key"]; } else { $chart_lbl_key = $this->ch_array["dataseries_label"]["key"]; $chart_lbl_val = $this->ch_array["dataseries_label"]["val"]; } // Sort Cols Values Array Start if ($this->report_obj->reportinformations["timeline_type2"] == "cols") { if ($this->report_obj->reportinformations["Sort2"] == "Descending") { krsort($this->ch_array["dataseries"]); krsort($this->ch_array["dataseries"]["subval"]); } else { ksort($this->ch_array["dataseries"]); ksort($this->ch_array["dataseries"]["subval"]); } } elseif ($this->report_obj->reportinformations["timeline_type3"] == "cols") { if ($this->report_obj->reportinformations["Sort3"] == "Descending") { krsort($this->ch_array["dataseries"]); krsort($this->ch_array["dataseries"]["subval"]); } else { ksort($this->ch_array["dataseries"]); ksort($this->ch_array["dataseries"]["subval"]); } } // Sort Cols Values Array End // Stack Horizontal Charts for better Look ;) if ($this->ch_array["charttype"] == "horizontal" && isset($this->ch_array["dataseries"]["subval"]) && !empty($this->ch_array["dataseries"]["subval"])) { $is_stacked = true; $dataseries[] = array($chart_lbl_key); } else { $dataseries[] = array($chart_lbl_key, $chart_lbl_val); } if (isset($this->ch_array["dataseries"]["subval"]) && !empty($this->ch_array["dataseries"]["subval"])) { if (isset($this->ch_array["dataseries_label"]["subval"]) && !empty($this->ch_array["dataseries_label"]["subval"])) { foreach ($this->ch_array["dataseries_label"]["subval"] as $sv_key => $sv_label) { $dataseries[0][] = $sv_label; } } } if ($is_stacked) { $ch_array_dataseries = $this->ch_array["dataseries"]["subval"]; } else { $ch_array_dataseries = $this->ch_array["dataseries"]; } foreach ($ch_array_dataseries as $ch_key => $ch_value) { $dataseries_arr = array(); if ($ch_key != "subval") { $ch_key_coded = $ch_key; $ch_key = html_entity_decode($ch_key, ENT_QUOTES, $default_charset); $ch_value = html_entity_decode($ch_value, ENT_QUOTES, $default_charset); settype($ch_value, "integer"); settype($ch_key, "string"); $dataseries_arr[] = $ch_key; if (!$is_stacked) { $dataseries_arr[] = $ch_value; } if (isset($this->ch_array["dataseries"]["subval"]) && !empty($this->ch_array["dataseries"]["subval"])) { if (isset($this->ch_array["dataseries"]["subval"][$ch_key]) && !empty($this->ch_array["dataseries"]["subval"][$ch_key])) { foreach ($this->ch_array["dataseries_label"]["subval"] as $sv_key => $sv_label) { if (isset($this->ch_array["dataseries"]["subval"][$ch_key][$sv_label])) { if (is_array($this->ch_array["dataseries"]["subval"][$ch_key][$sv_label][0])) { $ds_val = end($this->ch_array["dataseries"]["subval"][$ch_key][$sv_label][0]); } elseif (count($this->ch_array["dataseries"]["subval"][$ch_key][$sv_label]) > 1) { $ds_val = array_sum($this->ch_array["dataseries"]["subval"][$ch_key][$sv_label]); } else { $ds_val = $this->ch_array["dataseries"]["subval"][$ch_key][$sv_label][0]; } settype($ds_val, "integer"); $dataseries_arr = array_merge($dataseries_arr, array($ds_val)); } else { $dataseries_arr = array_merge($dataseries_arr, array(0)); } } } else { foreach ($this->ch_array["dataseries_label"]["subval"] as $sv_label) { $dataseries_arr = array_merge($dataseries_arr, array(0)); } } } $dataseries[] = $dataseries_arr; } } if ($charttype == "horizontal") { $yaxis_title = html_entity_decode($chart_lbl_val, ENT_QUOTES, $default_charset); $xaxis_title = html_entity_decode($chart_lbl_key, ENT_QUOTES, $default_charset); } else { $xaxis_title = html_entity_decode($chart_lbl_val, ENT_QUOTES, $default_charset); $yaxis_title = html_entity_decode($chart_lbl_key, ENT_QUOTES, $default_charset); } $ch_fld_ui_type = $chart_column_str = ""; if (isset($this->g_flds[0]) && !empty($this->g_flds[0])) { $ch_fld_as = $this->g_flds[0]; if (isset($this->columns_array["uitype_{$ch_fld_as}"]) && !empty($this->columns_array["uitype_{$ch_fld_as}"])) { $ch_fld_ui_type = $this->columns_array["uitype_{$ch_fld_as}"]; if (isset($this->columns_array[$ch_fld_as]) && !empty($this->columns_array[$ch_fld_as])) { $chart_column_str = $this->columns_array[$ch_fld_as]; } } } require_once 'modules/ITS4YouReports/gcharts.php'; $gcharts = new Gcharts(); $gcharts->chart_type = $charttype; $gcharts->report_filename = $this->report_filename; $gcharts->export_pdf_format = $export_pdf_format; $gcharts->chart_column_uitype = $ch_fld_ui_type; $gcharts->chart_column_str = $chart_column_str; $gcharts->is_currency = $currency_id; if (isset($this->g_chart_types[$charttype])) { $graphic_type = $this->g_chart_types[$charttype]; } else { $graphic_type = $this->g_chart_types["horizontal"]; } if ($graphic_type == "PieChart") { $chart_width = "600"; } else { $chart_width = "100%"; } $this->ch_image_name = $filename; $gcharts->load(array('graphic_type' => $graphic_type, 'ch_image_name' => $filename)); $set_options = array(); $set_options["width"] = $chart_width; $chart_height = "1000"; $chart_height = "800"; if ($is_stacked) { $set_options["isStacked"] = "true"; } $set_options["title"] = $charttitle; $set_options["vAxis"] = array('title' => "{$xaxis_title}"); $gch_height = "55%"; $gch_width = "60%"; if ($graphic_type == "PieChart") { $chart_height = "500"; $gch_height = "85%"; $gch_width = "100%"; $set_options["legend"] = array("position" => "right", "textStyle" => "{fontSize:5}"); if ($charttype == "pie3d") { $set_options["is3D"] = "true"; } } if ($charttype == "funnel") { $set_options["bar"] = array("groupWidth" => "100%"); } else { $set_options["bar"] = array("groupWidth" => "90%"); } $set_options["titleTextStyle"] = array("fontSize" => "25", "fontWidth" => "bold", "margin" => "auto"); $set_options["height"] = $chart_height; $hAxis_arr["textPosition"] = "out"; $hAxis_arr["slantedText"] = "false"; $hAxis_arr["maxAlternation"] = "255"; $hAxis_arr["maxTextLines"] = "255"; if ($charttype == "funnel") { $hAxis_arr["textPosition"] = "none"; } $hAxis_arr["title"] = "{$yaxis_title}"; $set_options["hAxis"] = $hAxis_arr; $set_options["chartArea"] = array('right' => "20%", 'width' => "{$gch_width}", 'height' => "{$gch_height}"); $gcharts->set_options($set_options); $report_html .= "<div id='break_row' class='no-print'></br></div>"; $report_html .= "<div id='chart_div' class='no-print' style='width:100%;text-align:center;'>\n <table class='rpt4youTableGraph' style='padding:0px;margin:auto;width:80%;height:auto;text-align:center;' cellpadding='5' cellspacing='0' align='center'>\n <tr>\n <td class='rpt4youGrpHead' nowrap='' align='center' style='text-align:center;border:0px;verical-align:top;'>"; $report_html .= $gcharts->generate($dataseries); $report_html .= "</td>\n </tr>\n </table></div>"; } //ITS4YouReports::sshow($dataseries); //return $dataseries; return $report_html; }
/** * Builds the Javascript code block * * This will build the script block for the actual chart and passes it * back to output function of the calling chart object. If there are any * events defined, they will be automatically be attached to the chart and * pulled from the callbacks folder. * * @param string Passed from the calling chart. * @return string Javascript code block. */ static function _build_script_block($chart) { self::$elementID = $chart->elementID; $out = self::$googleAPI . PHP_EOL; // if(isset($chart->events) && is_array($chart->events) && count($chart->events) > 0) // { // $out .= self::_build_event_callbacks($chart->chartType, $chart->events); // } $out .= self::$jsOpen . PHP_EOL; if ($chart->elementID == NULL) { $out .= 'alert("Error calling ' . $chart->chartType . '(\'' . $chart->chartLabel . '\')->outputInto(), requires a valid html elementID.");' . PHP_EOL; } if (isset($chart->data) === FALSE && isset(self::$dataTables[$chart->dataTable]) === FALSE) { $out .= 'alert("No DataTable has been defined for ' . $chart->chartType . '(\'' . $chart->chartLabel . '\').");' . PHP_EOL; } switch ($chart->chartType) { case 'AnnotatedTimeLine': $vizType = 'annotatedtimeline'; break; case 'GeoChart': $vizType = 'geochart'; break; default: $vizType = 'corechart'; break; } $out .= sprintf("google.load('visualization', '1', {'packages':['%s']});", $vizType) . PHP_EOL; $out .= 'google.setOnLoadCallback(drawChart);' . PHP_EOL; $out .= 'function drawChart() {' . PHP_EOL; if (isset($chart->data) && $chart->dataTable == 'local') { $data = $chart->data->toJSON(); $format = 'var data = new google.visualization.DataTable(%s, %s);'; $out .= sprintf($format, $data, self::$dataTableVersion) . PHP_EOL; } if (isset(self::$dataTables[$chart->dataTable])) { $data = self::$dataTables[$chart->dataTable]; $format = 'var data = new google.visualization.DataTable(%s, %s);'; $out .= sprintf($format, $data->toJSON(), self::$dataTableVersion) . PHP_EOL; } $out .= "var options = " . $chart->optionsToJSON() . ";" . PHP_EOL; $out .= "var chart = new google.visualization." . $chart->chartType; $out .= sprintf("(document.getElementById('%s'));", $chart->elementID) . PHP_EOL; $out .= "chart.draw(data, options);" . PHP_EOL; // if(isset($chart->events) && count($chart->events) > 0) // { // foreach($chart->events as $event) // { // $out .= sprintf('google.visualization.events.addListener(chart, "%s", ', $event); // $out .= sprintf('function(event) { %s.%s(event); });', $chart->chartType, $event).PHP_EOL; // } // } $out .= "}" . PHP_EOL; $out .= self::$jsClose . PHP_EOL; self::$output = $out; return self::$output; }
/** * Whether to guess the value of missing points. If true, it will guess the * value of any missing data based on neighboring points. If false, it will * leave a break in the line at the unknown point. * * @param boolean $interpolateNulls * @return \AreaChart */ public function interpolateNulls($interpolateNulls) { if (is_bool($interpolateNulls)) { $this->addOption(array('interpolateNulls' => $interpolateNulls)); } else { Gcharts::_set_error($where, 'Invalid interpolateNulls value, must be type (boolean).'); } return $this; }