MINI
C:
/
SiakApp2.2
/
lib
/
Upload File:
files >> C:/SiakApp2.2/lib/SiakChart.php
<?php require_once 'chart/phplot.php'; function siakChartBar($data,$legen,$judul,$tipe,$lebar=950,$tinggi=600){ # Define the data array: Label, the 3 data sets. # Year, Features, Bugs, Happy Users: # Create a PHPlot object which will make a 600x400 pixel image: //get max data $p = new PHPlot($lebar, $tinggi); # Use TrueType fonts: $p->SetDefaultTTFont(dirname(__FILE__).'/chart/arial.ttf'); # Set the main plot title: $p->SetTitle($judul); $maximalData=0; foreach($data as $baris){ for($i=1;$i<count($baris);$i++){ if($maximalData<$baris[$i]) $maximalData=$baris[$i]; } } $maximalData+=$maximalData*0.05; # Select the data array representation and store the data: $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetXLabelAngle(35); # Select the plot type - bar chart: $p->SetPlotType('bars'); # Define the data range. PHPlot can do this automatically, but not as well. if(count($data)==1) $p->SetPlotAreaWorld(-1, 0, count($data)+2, $maximalData); elseif(count($data)==2) $p->SetPlotAreaWorld(0, 0, count($data)+1, $maximalData); else $p->SetPlotAreaWorld(0, 0, count($data)+1, $maximalData); # Select an overall image background color and another color under the plot: $p->SetBackgroundColor('#cccccc'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('#ffffff'); $listColor=array('DarkGreen', 'DimGrey', 'PeachPuff', 'SkyBlue', 'SlateBlue', 'YellowGreen', 'aquamarine1', 'azure1', 'beige', 'black','blue','brown', 'cyan', 'gold','gray','green','ivory', 'lavender','magenta','maroon','navy','orange','orchid', 'peru','pink','plum','purple','red','salmon', 'snow','tan','violet','wheat','white','yellow'); $useColor=array(); for($i=0;$i<count($data[0])-1;$i++){ $useColor[$i]=$listColor[$i%35]; } //print_r($useColor); $p->SetDataColors($useColor); # Draw lines on all 4 sides of the plot: $p->SetPlotBorderType('full'); # Set a 3 line legend, and position it in the upper left corner: $p->SetLegend($legen); //$p->SetLegendWorld(count($data), $maximalData-5); # Turn data labels on, and all ticks and tick labels off: $p->SetXDataLabelPos('plotdown'); /*$p->SetYTickPos('none'); $p->SetYTickLabelPos('none');*/ $p->SetXTickPos('none'); $p->SetXTickLabelPos('none'); $p->SetYDataLabelPos('plotin'); $p->SetFileFormat('png'); $p->SetPrintImage(true); $p->SetIsInline(true); # Generate and output the graph now: $output_file="/chart/".$tipe.".png"; $p->SetOutputFile(getcwd().$output_file); $p->DrawGraph(); return $output_file; //return getcwd().$output_file; } /*============================================================================================================================*/ function siakPieBar($data,$judul,$tipe,$lebar=950,$tinggi=600){ # PHPlot Example: Pie/text-data-single # The data labels aren't used directly by PHPlot. They are here for our # reference, and we copy them to the legend below. $plot = new PHPlot($lebar,$tinggi); $plot->SetImageBorderType('plain'); $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); # Set enough different colors; $listColor=array('DarkGreen', 'DimGrey', 'PeachPuff', 'SkyBlue', 'SlateBlue', 'YellowGreen', 'aquamarine1', 'azure1', 'beige', 'black','blue','brown', 'cyan', 'gold','gray','green','ivory', 'lavender','magenta','maroon','navy','orange','orchid', 'peru','pink','plum','purple','red','salmon', 'snow','tan','violet','wheat','white','yellow'); $useColor=array(); $besar=0; for($i=0;$i<count($data);$i++){ $useColor[$i]=$listColor[$i%35]; if($besar<$data[$i][1]) $besar=$data; } if($besar==0){ $data=array(array('Tidak ada data',1)); } $plot->SetDataColors($useColor); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle($judul); # Build a legend from our data array. # Each call to SetLegend makes one line as "label: value". foreach ($data as $row) $plot->SetLegend(implode(': ', $row)); $output_file="/chart/".$tipe.".png"; $plot->SetOutputFile(getcwd().$output_file); $plot->SetIsInline(true); $plot->DrawGraph(); return $output_file; } function pickcolor($img, $data_array, $row, $col){ $d = $data_array[$row][2]; // col+1 skips over the row's label if ($d >= 0) return 0; if ($d < 0) return 1; } function SiakChartPr($data,$x,$y,$judul,$Namafile,$lebar=950,$tinggi=600){ $plot = new PHPlot($lebar, $tinggi); $plot->SetImageBorderType('plain'); // Improves presentation in the manual //$plot->SetUseTTF(True); $plot->SetTitle($judul); $plot->SetXTitle($x); // 179=superscript 3 $plot->SetYTitle($y); // 176=degrees $plot->SetPlotType('thinbarline'); $plot->SetDataType('data-data-yx'); $plot->SetDataColors(array('blue','red')); $dataChart=array(); $maxLk=0; $maxPr=0; for($i=1,$umur=4;$i<=16;$i++,$umur+=5){ $dataChart[]=array('',$umur,$data[0]['COL'.tambahnol($i,2)]); $dataChart[]=array('',$umur,$data[1]['COL'.tambahnol($i,2)]*(-1));; if($maxLk<$data[0]['COL'.tambahnol($i,2)]) $maxLk=$data[0]['COL'.tambahnol($i,2)]; if($maxPr<$data[1]['COL'.tambahnol($i,2)]) $maxPr=$data[1]['COL'.tambahnol($i,2)]; } $plot->SetCallback('data_color', 'pickcolor', $dataChart); $plot->SetDataColors(array('blue','red')); $plot->SetDataValues($dataChart); $plot->SetPlotAreaWorld($maxPr*(-1), 0, $maxLk, 80); $plot->SetLineWidths(20); $output_file="/chart/".$Namafile; $plot->SetOutputFile(getcwd().$output_file); $plot->SetIsInline(true); $plot->DrawGraph(); return $output_file; }
Copyright ©2021 || Defacer Indonesia