function pch_vertical_graph($graph_type, $index, $data, $width, $height, $rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false, $legend = array(), $font, $antialiasing, $water_mark = '', $font_size) { /* CAT:Vertical Charts */ if (!is_array($legend) || empty($legend)) { unset($legend); } /*$legend=array('pep1' => 'pep1','pep2' => 'pep2','pep3' => 'pep3','pep4' => 'pep4'); $data=array(array('pep1' => 1, 'pep2' => 1, 'pep3' => 3, 'pep4' => 3), array('pep1' => 1, 'pep2' => 3, 'pep3' => 1,'pep4' => 4), array('pep1' => 3, 'pep2' => 1, 'pep3' => 1,'pep4' =>1), array('pep1' => 1, 'pep2' =>1, 'pep3' =>1,'pep4' =>0)); $index=array(1,2,3,4); */ if (is_array(reset($data))) { $data2 = array(); foreach ($data as $i => $values) { $c = 0; foreach ($values as $i2 => $value) { $data2[$i2][$i] = $value; $c++; } } $data = $data2; } else { $data = array($data); } /* Create and populate the pData object */ $MyData = new pData(); foreach ($data as $i => $values) { if (isset($legend)) { $point_id = $legend[$i]; } else { $point_id = $i; } $MyData->addPoints($values, $point_id); if (!empty($rgb_color)) { $MyData->setPalette($point_id, array("R" => $rgb_color[$i]['color']["R"], "G" => $rgb_color[$i]['color']["G"], "B" => $rgb_color[$i]['color']["B"], "BorderR" => $rgb_color[$i]['border']["R"], "BorderG" => $rgb_color[$i]['border']["G"], "BorderB" => $rgb_color[$i]['border']["B"], "Alpha" => $rgb_color[$i]['alpha'])); /*$palette_color = array(); if (isset($rgb_color[$i]['color'])) { $palette_color["R"] = $rgb_color[$i]['color']["R"]; $palette_color["G"] = $rgb_color[$i]['color']["G"]; $palette_color["B"] = $rgb_color[$i]['color']["B"]; } if (isset($rgb_color[$i]['color'])) { $palette_color["BorderR"] = $rgb_color[$i]['border']["R"]; $palette_color["BorderG"] = $rgb_color[$i]['border']["G"]; $palette_color["BorderB"] = $rgb_color[$i]['border']["B"]; } if (isset($rgb_color[$i]['color'])) { $palette_color["Alpha"] = $rgb_color[$i]['Alpha']; } $MyData->setPalette($point_id, $palette_color);*/ } $MyData->setSerieWeight($point_id, 1); } //$MyData->addPoints($data,"Yaxis"); $MyData->setAxisName(0, $yaxisname); $MyData->addPoints($index, "Xaxis"); $MyData->setSerieDescription("Xaxis", $xaxisname); $MyData->setAbscissa("Xaxis"); /* Create the pChart object */ $myPicture = new pImage($width, $height, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = $antialiasing; /* Add a border to the picture */ //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size)); if (isset($legend)) { /* Set horizontal legend if is posible */ $legend_mode = LEGEND_HORIZONTAL; $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); if ($size['Width'] > $width - 5) { $legend_mode = LEGEND_VERTICAL; $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); } /* Write the chart legend */ $myPicture->drawLegend($width - $size['Width'], 8, array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); } //Calculate the bottom margin from the size of string in each index $max_chars = 0; foreach ($index as $string_index) { if (empty($string_index)) { continue; } $len = strlen($string_index); if ($len > $max_chars) { $max_chars = $len; } } $margin_bottom = 10 * $max_chars; $water_mark_height = 0; $water_mark_width = 0; if (!empty($water_mark)) { $size_water_mark = getimagesize($water_mark); $water_mark_height = $size_water_mark[1]; $water_mark_width = $size_water_mark[0]; $myPicture->drawFromPNG($width - $water_mark_width, $height - $water_mark_height - $margin_bottom, $water_mark); } if (isset($size['Height'])) { /* Define the chart area */ $myPicture->setGraphArea(40, $size['Height'], $width - $water_mark_width, $height - $margin_bottom); } else { /* Define the chart area */ $myPicture->setGraphArea(40, 5, $width - $water_mark_width, $height - $margin_bottom); } /* Draw the scale */ $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_START0, "LabelRotation" => 60, "XMargin" => 0); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); switch ($graph_type) { case 'stacked_area': $ForceTransparency = "-1"; break; default: $ForceTransparency = "50"; break; } /* Draw the chart */ $settings = array("ForceTransparency" => $ForceTransparency, "Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayValues" => $show_values, "DisplayZeroValues" => FALSE, "DisplayR" => 100, "DisplayZeros" => FALSE, "DisplayG" => 100, "DisplayB" => 100, "DisplayShadow" => TRUE, "Surrounding" => 5, "AroundZero" => FALSE); switch ($graph_type) { case "stacked_area": case "area": $myPicture->drawAreaChart($settings); break; case "line": $myPicture->drawLineChart($settings); break; } /* Render the picture */ $myPicture->stroke(); }
} else { if (isset($chart_cols2) and in_array($idx, $chart_cols2)) { $arrSeriesY2[] = $field; $myData->setSerieOnAxis($field, 1); $myData->setSerieDescription($field, "右){$field}"); } } $nSerie += 1; } } if (isset($arrSeriesY2)) { $myData->setAxisPosition(1, AXIS_POSITION_RIGHT); } $myData->setAxisUnit(0, $unitY); /* Write the chart legend */ $sizeLegend = $myPicture->getLegendSize(array("Mode" => LEGEND_VERTICAL)); $widthLegend = min($sizeLegend['Width'], max(120, $width * 0.25)); if ($legend > 0) { $myPicture->setFontProperties(array("FontName" => "./fonts/simsun.ttc", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); $myPicture->drawLegend($width - 5 - $widthLegend, 5 + $font_t * 3, array("Style" => LEGEND_BOX, "Mode" => LEGEND_VERTICAL, "Alpha" => 10, "Margin" => 4, "R" => 255, "G" => 255, "B" => 255)); } $myPicture->setFontProperties(array("FontName" => "./fonts/simhei.ttf", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); /* Define the chart area */ $width_offset = 0; if ($legend > 0) { $width_offset += max($widthLegend, 50); } if (isset($arrSeriesY2)) { $width_offset += 15 + $font * 3; } $myPicture->setGraphArea(28 + $font * 3, 11 + $font_t * 3, $width - 15 - $width_offset, $height - 23 - $font * 3);
if ($l_format == "LEGEND_ROUND") { $Config["Style"] = 690802; } if ($l_orientation == "LEGEND_VERTICAL") { $Config["Mode"] = 690901; } if ($l_orientation == "LEGEND_HORIZONTAL") { $Config["Mode"] = 690902; } if ($l_family == "LEGEND_FAMILY_CIRCLE") { $Config["Family"] = 691052; } if ($l_family == "LEGEND_FAMILY_LINE") { $Config["Family"] = 691053; } $Size = $myPicture->getLegendSize($Config); if ($l_position == "CORNER_TOP_RIGHT") { $l_y = $l_margin + 10; $l_x = $g_width - $Size["Width"] - 10 + $l_margin; } if ($l_position == "CORNER_BOTTOM_RIGHT") { $l_y = $g_height - $Size["Height"] - 10 + $l_margin; $l_x = $g_width - $Size["Width"] - 10 + $l_margin; } if ($Mode == "Render") { $myPicture->drawLegend($l_x, $l_y, $Config); } else { $Config["FontName"] = chr(34) . "fonts/" . $l_font . chr(34); echo "\r\n"; echo dumpArray("Config", $Config); echo '$myPicture->drawLegend(' . $l_x . ',' . $l_y . ',$Config);' . "\r\n";