function drawChart($title, $DataSet, $names, $colors, $legend = false) { // Initialise the graph $Chart = new pChart(1300, 750); $Chart->setFontProperties("Fonts/tahoma.ttf", 8); $Chart->setGraphArea(50, 25, 1200, 725); $Chart->drawGraphArea(255, 255, 255, TRUE); $Chart->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "ally", "allx", 150, 150, 150, TRUE, 45); $Chart->setLineStyle(4); // Draw the 0 line $Chart->setFontProperties("Fonts/tahoma.ttf", 6); $Chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); foreach ($colors as $idx => $color) { $Chart->setColorPalette($idx, $color[0], $color[1], $color[2]); } $i = 0; foreach ($names as $name) { $Chart->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $name . "y", $name . "x", $i); $i++; } if ($legend) { $Chart->drawLegend(465, 40, $DataSet->GetDataDescription(), 255, 255, 255); } // Finish the graph $Chart->setFontProperties("Fonts/tahoma.ttf", 10); // $Chart->drawTitle(60,22,$title,50,50,50,530); $Chart->Stroke(); }
public function make($working_path) { // This will import the file http://my.domain.com/myData.csv using each column as a serie if (!$this->plot->valid()) { $file = $this->plot->name(); $error = $this->plot->error(); $this->log($working_path, "Plot file {$file} is invalid: {$error}"); return 1; } $data = new pData(); $columns = array(); $all_columns = array(); $x_column = $this->plot->property('x_column') - 1; if ($x_column === NULL) { $x_column = 0; } $data_file = $this->plot->data_property('name'); $deliminator = $this->plot->data_property('deliminator'); $has_header = $this->plot->data_property('header') == 'yes'; foreach ($this->plot->columns() as $column => $name) { if ($column != $x_column + 1) { $columns[] = $column - 1; } $all_columns[] = $column - 1; } $data->ImportFromCSV($working_path . $data_file, $deliminator, $all_columns, $has_header); foreach ($columns as $column) { $name = $this->plot->column($column + 1); $data->AddSerie('Serie' . $column); $data->SetSerieName($name, "Serie" . $column); } $max_col = -1; $max_val = NULL; foreach ($data->GetData() as $record) { foreach ($columns as $column) { $point = $record['Serie' . $column]; if ($max_val === NULL || $point > $max_val) { $max_val = $point; $max_col = $column; } } } $x_label = $this->plot->axis_property('x', 'label'); if ($x_label) { $data->SetXAxisName($x_label); } else { $data->SetXAxisName($this->plot->column($x_column + 1)); } $x_unit = $this->plot->axis_property('x', 'unit'); if ($x_unit) { $data->SetXAxisUnit($x_unit); } $y_label = $this->plot->axis_property('y', 'label'); reset($columns); if ($y_label) { $data->SetYAxisName($y_label); } else { $data->SetYAxisName($this->plot->column(current($columns) + 1)); } $y_unit = $this->plot->axis_property('y', 'unit'); if ($y_unit) { $data->SetyAxisUnit($y_unit); } $width = $this->plot->property('width'); if (!$width) { $width = 640; } $height = $this->plot->property('height'); if (!$height) { $height = 480; } $plot = new pChart($width, $height); $font_name = $this->plot->property('font-name'); if (!$font_name) { $font_name = 'tahoma.ttf'; } $font_name = 'lib/plugins/projects/pchart/fonts/' . $font_name; $font_size = $this->plot->property('font_size'); if (!$font_size) { $font_size = 12; } $plot->setFontProperties($font_name, $font_size); $h = $font_size + 10; $left_margin = 0; foreach ($data->GetData() as $record) { $position = imageftbbox($font_size, 0, $font_name, $record['Serie' . $max_col]); $text_width = $position[2] - $position[0]; if ($text_width > $left_margin) { $left_margin = $text_width; } } $left_margin += 2 * $h; $plot->setGraphArea($left_margin, 2 * $h, $width - $h, $height - 2 * $h); $background = $this->plot->property('background'); if (!$background) { $background = array('R' => 255, 'G' => 255, 'B' => 255); } else { $background = html_color_to_RGB($background); } $plot->drawGraphArea($background['R'], $background['G'], $background['B']); // pick the largest scale $plot->drawXYScale($data->GetData(), $data->GetDataDescription(), 'Serie' . $max_col, 'Serie' . $x_column, 0, 0, 0, TRUE, 0, 0); $line_no = 0; $colors = array(); foreach ($columns as $column) { $name = $this->plot->column($column + 1); $style = $this->plot->line_style($name, 'style'); $line_color = $this->plot->line_style($name, 'color'); if (!$line_color) { $colors[$name] = array('R' => 0, 'G' => 0, 'B' => 0); } else { $colors[$name] = html_color_to_RGB($line_color); } $plot->setColorPalette($line_no, $colors[$name]['R'], $colors[$name]['G'], $colors[$name]['B']); if (!$style || $style == 'line' || $style == 'both') { $line_width = $this->plot->line_style($name, 'width'); if (!$line_width) { $line_width = 1; } $dot_size = $this->plot->line_style($name, 'dot-size'); if (!$dot_size) { $dot_size = 0; } $plot->setLineStyle($line_width, $dot_size); $plot->drawXYGraph($data->GetData(), $data->GetDataDescription(), 'Serie' . $column, 'Serie' . $x_column, $line_no); } if ($style == 'point' || $style == 'both') { $radius = $this->plot->line_style($name, 'radius'); if (!$radius) { $radius = 5; } $plot->drawXYPlotGraph($data->GetData(), $data->GetDataDescription(), 'Serie' . $column, 'Serie' . $x_column, $line_no, $radius, $radius - 2); } $line_no++; } $title = $this->plot->property('title'); foreach ($columns as $column) { $data->removeSerie('Serie' . $column); } $in_legend = array(); $description = $data->GetDataDescription(); $description['Description'] = array(); $palette_id = 0; foreach ($columns as $column) { $name = $this->plot->column($column + 1); if (in_array($name, $in_legend)) { continue; } $in_legend[] = $name; $description['Description']['Serie' . $column] = $name; $plot->setColorPalette($palette_id, $colors[$name]['R'], $colors[$name]['G'], $colors[$name]['B']); ++$palette_id; } $legend_box_size = $plot->getLegendBoxSize($description); $legend_position = $this->plot->property('legend-position'); if (!$legend_position) { $legend_position = 'top-left'; } switch ($legend_position) { case 'top-left': $legend_left = 0; $legend_top = 0; break; case 'top': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = 0; break; case 'top-right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = 0; break; case 'left': $legend_left = 0; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'center': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'bottom-left': $legend_left = 0; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; case 'bottom': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; case 'bottom-right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; } $plot->drawLegend($left_margin + $legend_left, 2 * $h + $legend_top, $description, 255, 255, 255, 100, 100, 100, 0, 0, 0, true); $plot->drawTitle($h, 0, $title, 0, 0, 0, $width - $h, $h * 2, 100); $plot->Render($this->path($working_path)); $file_name = $this->plot->name(); $plot_name = $this->name(); $this->log($working_path, "Successfully plotted {$file_name} as {$plot_name}\ntitle: {$title}\n"); return 0; }
function generate_graph_image($outputfile) { // Create Graph Dataset and set axis attributes $graphData = new pData(); $graphData->setYAxisName($this->ytitle); $graphData->AddPoint($this->xlabels, "xaxis"); //$graphData->SetSerieName("xaxis","xaxis"); $graphData->SetAbsciseLabelSerie("xaxis"); $graphData->setXAxisName($this->xtitle); // Add each series of plot values to dataset, but Reportico will // duplicate series were the same data are displayed in different forms // so only add each unique series once $seriesadded = array(); foreach ($this->plot as $k => $v) { $series = $v["name"] . $k; $graphData->AddPoint($v["data"], $series); $graphData->SetSerieName($v["legend"], $series); $graphData->AddSerie($series); } /* switch ( $this->xgriddisplay ) { case "all": $graph->xgrid->Show(true,true); break; case "major": $graph->xgrid->Show(true,false); break; case "minor": $graph->xgrid->Show(false,true); break; case "none": default: $graph->xgrid->Show(false,false); break; } switch ( $this->ygriddisplay ) { case "all": $graph->ygrid->Show(true,true); break; case "major": $graph->ygrid->Show(true,false); break; case "minor": $graph->ygrid->Show(false,true); break; case "none": default: $graph->ygrid->Show(false,false); break; } */ /* $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize); $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor); $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize); $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor); $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize); $graph->xaxis->title->SetColor($xtitlecolor); $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize); $graph->yaxis->title->SetColor($ytitlecolor); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(15); $graph->yaxis->SetLabelMargin(15); $graph->xaxis->SetTickLabels($this->xlabels); $graph->xaxis->SetTextLabelInterval($xticklabint); $graph->yaxis->SetTextLabelInterval($yticklabint); $graph->xaxis->SetTextTickInterval($xtickinterval); $graph->yaxis->SetTextTickInterval($ytickinterval); */ /* if ( $gridpos == "front" ) $graph->SetGridDepth(DEPTH_FRONT); */ // Display the graph /*?$graph->Stroke();*/ $this->apply_defaults_internal(); //echo $this->width_pdf_actual.",".$this->height_pdf_actual."<BR>"; $graphImage = new pChart($this->width_pdf_actual, $this->height_pdf_actual); /* Turn of Antialiasing */ $graphImage->Antialias = TRUE; // Add gradient fill from chosen background color to white $startgradient = htmltorgb("#ffffff"); //$graphImage->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,array( //"StartR"=>$startgradient[0], "StartG"=>$startgradient[1], "StartB"=>$startgradient[2], //"EndR"=>$color[0], "EndG"=>$color[1], "EndB"=>$color[2],"Alpha"=>100)); /* Add a border to the picture */ //$graphImage->drawRectangle(0,0,$width - 1,$height - 1,200,200,200); $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xaxisfont, $this->xaxisfontsize); /* Define the chart area */ $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright_actual, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawFilledRoundedRectangle(3, 3, $this->width_pdf_actual - 3, $this->height_pdf_actual - 3, 5, 240, 240, 240); $graphImage->drawRoundedRectangle(1, 1, $this->width_pdf_actual - 1, $this->height_pdf_actual - 1, 5, 230, 230, 230); // Before plotting a series ensure they are all not drawable. /// Plot the chart data $stackeddrawn = false; $linedrawn = false; $scatterdrawn = false; $piedrawn = false; $stackedexists = false; $overlayexists = false; $barexists = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "OVERLAYBAR") { $overlayexists = true; } if ($v["type"] == "STACKEDBAR") { $stackedexists = true; } if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") { $barexists = true; } // Set plot colors if ($v["linecolor"]) { $graphImage->Palette[$k] = htmltorgb_pchart($v["linecolor"]); } $url .= "&plotlinecolor{$k}=" . $v["linecolor"]; } $scale_drawing_mode = SCALE_NORMAL; $scale_drawing_mode = SCALE_START0; // For stacked charts fix up the Max and Min values; if ($stackedexists) { $scale_drawing_mode = SCALE_ADDALL; $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $scaleMax = $scaleMax + $max; } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); } else { if ($barexists || $overlayexists) { $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } if ($scaleMax == "Unknown" || $max > $scaleMax) { $scaleMax = $max; } } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); } } //echo "<PRE>"; //var_dump($graphData->GetDataDescription()); //die; // Find out if a scale is required, will be except for pie charts $scalerequired = false; foreach ($this->plot as $k => $v) { switch ($v["type"]) { case "BAR": case "STACKEDBAR": case "OVERLAYBAR": case "LINE": $scalerequired = "NORMAL"; break; case "SCATTER": $scalerequired = "SCATTER"; break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->xtitlefontsize); if ($scalerequired) { $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawGraphAreaGradient(240, 240, 240, -20); // Automatic generation of x tick interval based on number of ticks if ($this->xticklabelinterval_actual == "AUTO") { $labct = count($this->plot[0]["data"]); $this->xticklabelinterval_actual = floor($labct / 35) + 1; } if ($scalerequired == "NORMAL") { $graphImage->drawScale($graphData->GetData(), $graphData->GetDataDescription(), $scale_drawing_mode, 0, 0, 0, TRUE, 40, FALSE, TRUE, $this->xticklabelinterval_actual, FALSE); } $graphImage->drawGrid(2, TRUE, 230, 230, 230, 45); } else { $this->marginright = 5; $this->marginbottom = 5; $this->marginleft = 5; $this->marginright_actual = 5; $this->marginbottom_actual = 5; $this->marginleft_actual = 5; //$this->margintop_actual = 5; $graphImage->setGraphArea($this->marginleft, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom); $graphImage->drawGraphAreaGradient(240, 240, 240, -10); } // If there's a Pie chart we want to draw different legends $piechart = false; foreach ($this->plot as $k => $v) { disableAllSeries($this->plot, $graphData); $series = $v["name"] . $k; setSerieDrawable($this->plot, $graphData, $series, TRUE); switch ($v["type"]) { case "PIE": $piedrawn = true; $piechart = true; $graphImage->drawFilledCircle($this->width_pdf_actual / 2 + 2, $this->margintop_actual + 2 + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45 + 1, 200, 200, 200); $graphImage->drawBasicPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45, PIE_PERCENTAGE_LABEL, 255, 255, 218); break; case "PIE3D": $piedrawn = true; $piechart = true; $graphImage->drawPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.5, PIE_PERCENTAGE_LABEL, true, 60, 20, 0, 0); break; case "OVERLAYBAR": case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists || $overlayexists) { foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR" || $v1["type"] == "OVERLAYBAR") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } } $stackeddrawn = true; if ($stackedexists) { $graphImage->drawStackedBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { if ($overlayexists) { $graphImage->drawOverlayBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { $graphImage->drawBarGraph($graphData->GetData(), $graphData->GetDataDescription()); } } break; case "SCATTER": if ($scatterdrawn) { break; } $scatterdrawn = true; $series1 = false; $series2 = false; $graphImage->reportWarnings("GD"); $ct = 0; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "SCATTER") { if ($ct == 0) { $series1 = $v1["name"] . $k1; } if ($ct == 1) { $series2 = $v1["name"] . $k1; } $ct++; setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0); //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2); break; case "LINE": default: if ($linedrawn) { break; } $linedrawn = true; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "LINE") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->LineWidth = 1; $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->LineWidth = 1; break; } } foreach ($this->plot as $k1 => $v1) { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } // Draw Legend if legend value has been set $drawlegend = false; foreach ($this->plot as $k => $v) { if (isset($v["legend"]) && $v["legend"]) { // Temporarily Dont draw legend for Pie //if ( $piechart ) //$graphImage->drawPieLegend($this->width_pdf_actual - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250); if (!$piechart) { $graphImage->drawLegend($this->width_pdf_actual - 120, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0); } break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->titlefontsize); $graphImage->drawTitle(0, 24, $this->title_actual, 50, 50, 50, $this->width_pdf_actual); //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); //$graphImage->Render("example.png"); //$graphImage->Stroke(); $graphImage->render($outputfile); return true; }
foreach ($plot as $k1 => $v1) { if ($v1["type"] == "SCATTER") { if ($ct == 0) { $series1 = $v1["name"] . $k1; } if ($ct == 1) { $series2 = $v1["name"] . $k1; } $ct++; setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0); //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2); break; case "LINE": default: if ($linedrawn) { break; } $linedrawn = true; foreach ($plot as $k1 => $v1) { if ($v1["type"] == "LINE") { setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE); } }
public function testDrawXYPlotGraph() { $dataSet = new pData(); $dataSet->addPoints(array(1, 3, 2, 6, 3, 1), 'X'); $dataSet->addPoints(array(5, 2, 4, 12, 7, 3), 'Y'); $dataSet->addSeries('X'); $dataSet->addSeries('Y'); $canvas = new TestCanvas(); $chart = new pChart(300, 300, $canvas); $chart->setFontProperties('Fonts/tahoma.ttf', 8); $chart->setGraphArea(55, 30, 270, 230); $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(213, 217, 221)); $chart->drawXYScale($dataSet, $scaleStyle, 'Y', 'X', 45); $backgroundStyle = new BackgroundStyle(new Color(213, 217, 221), FALSE); $chart->drawGraphBackground($backgroundStyle); $chart->drawGrid(new GridStyle(4, TRUE, new Color(230), 20)); $chart->drawXYPlotGraph($dataSet->getData(), 'Y', 'X'); file_put_contents(dirname(__FILE__) . '/action_logs/testDrawXYPlotGraph', $canvas->getActionLog()); $this->assertEquals('a769bf6298734bb20665fc27f7f462ab', md5($canvas->getActionLog())); }
public function resolution() { $result = $this->hlp->Query()->resolution($this->tlimit, 0, 100); $data1 = array(); $data2 = array(); $data3 = array(); foreach ($result as $row) { $data1[] = $row['res_x']; $data2[] = $row['res_y']; $data3[] = $row['cnt']; } $DataSet = new pData(); $DataSet->AddPoints($data1, 'Serie1'); $DataSet->AddPoints($data2, 'Serie2'); $DataSet->AddPoints($data3, 'Serie3'); $DataSet->AddAllSeries(); $Canvas = new GDCanvas(650, 490, false); $Chart = new pChart(650, 490, $Canvas); $Chart->setFontProperties(dirname(__FILE__) . '/pchart/Fonts/DroidSans.ttf', 8); $Chart->setGraphArea(50, 30, 630, 470); $Chart->drawXYScale($DataSet, new ScaleStyle(SCALE_NORMAL, new Color(127)), 'Serie2', 'Serie1'); $Chart->drawXYPlotGraph($DataSet, 'Serie2', 'Serie1', 0, 20, 2, null, false, 'Serie3'); header('Content-Type: image/png'); $Chart->Render(''); }
for ($i = 0; $i <= 360; $i = $i + 10) { $DataSet->AddPoint(cos($i * 3.14 / 180) * 80 + $i, "Serie1"); $DataSet->AddPoint(sin($i * 3.14 / 180) * 80 + $i, "Serie2"); } $DataSet->SetSerieName("Trigonometric function", "Serie1"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetXAxisName("X Axis"); $DataSet->SetYAxisName("Y Axis"); // Initialise the graph $Test = new pChart(300, 300); $Test->drawGraphAreaGradient(0, 0, 0, -100, TARGET_BACKGROUND); // Prepare the graph area $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 30, 270, 230); $Test->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 213, 217, 221, TRUE, 45); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawGraphAreaGradient(30, 30, 30, -50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the chart $Test->setShadowProperties(2, 2, 0, 0, 0, 60, 4); $Test->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 0); $Test->clearShadow(); // Draw the title $Title = "Drawing X versus Y charts trigonometric functions "; $Test->drawTextBox(0, 280, 300, 300, $Title, 0, 255, 255, 255, ALIGN_RIGHT, TRUE, 0, 0, 0, 30); // Draw the legend $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $DataSet->RemoveSerie("Serie2"); $Test->drawLegend(160, 5, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, 255, 255, 255, FALSE); $Test->Stroke("example24.png");