Ich arbeite mit der jpgraph und Erstellen von Radar-Diagramm.Füllen Sie die Farbverlauf in meiner benutzerdefinierten Form Polygon jpgraph
Das Problem mit dem Füllen von benutzerdefinierten Form Polygon mit Farbverlauf konfrontiert.
Ich habe Funktion, um ein Farbverlaufsfarbpolygon mit einem flachen Boden zu füllen, und ich möchte die Farbverlaufsfarbe in meinem benutzerdefinierten Formpolygon füllen. Kann mir jemand helfen? Wie kann ich das machen?
Stromausgang:
gewünschte Ausgabe:
Sie können hier die Steigung Klasse finden.
// Fill a special case of a polygon with a flat bottom
// with a gradient. Can be used for filled line plots.
// Please note that this is NOT a generic gradient polygon fill
// routine. It assumes that the bottom is flat (like a drawing
// of a mountain)
function FilledFlatPolygon($pts,$from_color,$to_color) {
if(count($pts) == 0) return;
$maxy=$pts[1];
$miny=$pts[1];
$n = count($pts) ;
for($i=0, $idx=0; $i < $n; $i += 2) {
$x = round($pts[$i]);
$y = round($pts[$i+1]);
$miny = min($miny,$y);
$maxy = max($maxy,$y);
}
$colors = array();
$this->GetColArray($from_color,$to_color,abs($maxy-$miny)+1,$colors,$this->numcolors);
for($i=$miny, $idx=0; $i <= $maxy; ++$i) {
$colmap[$i] = $colors[$idx++];
}
$n = count($pts)/2 ;
$idx = 0 ;
while($idx < $n-1) {
$p1 = array(round($pts[$idx*2]),round($pts[$idx*2+1]));
$p2 = array(round($pts[++$idx*2]),round($pts[$idx*2+1]));
// Find the largest rectangle we can fill
$y = max($p1[1],$p2[1]) ;
for($yy=$maxy; $yy > $y; --$yy) {
$this->img->current_color = $colmap[$yy];
$this->img->Line($p1[0],$yy,$p2[0]-1,$yy);
}
if($p1[1] == $p2[1]) continue;
// Fill the rest using lines (slow...)
$slope = ($p2[0]-$p1[0])/($p1[1]-$p2[1]);
$x1 = $p1[0];
$x2 = $p2[0]-1;
$start = $y;
if($p1[1] > $p2[1]) {
while($y >= $p2[1]) {
$x1=$slope*($start-$y)+$p1[0];
$this->img->current_color = $colmap[$y];
$this->img->Line($x1,$y,$x2,$y);
--$y;
}
}
else {
while($y >= $p1[1]) {
$x2=$p2[0]+$slope*($start-$y);
$this->img->current_color = $colmap[$y];
$this->img->Line($x1,$y,$x2,$y);
--$y;
}
}
}
}
Vielleicht möchten Sie Ihren Code zur Verfügung stellen, damit er reproduziert werden kann. – spenibus