20) $colors[$i] = 0x00ff00; else $colors[$i] = 0xffff00; } $borderColor = 0x000000; #chart width, margin and rotation angle $chartWidth = 640; $margin = 30; $angle = 30; $hFlip = true; #compute cell size and adjust chart width to a multiple of cell size $cellWidth = ($chartWidth - $margin * 2) / $width; $chartWidth = $cellWidth * $width + $margin * 2; #plot the cells $c = new XYChart($chartWidth, $chartWidth); $d = $c->getDrawArea(); for ($x = 0; $x < $width; ++$x) { for ($y = 0; $y < $width; ++$y) { $leftX = $margin + $cellWidth * $x; $topY = $margin + $cellWidth * $y; $rightX = $leftX + $cellWidth; $bottomY = $topY + $cellWidth; $d->rect($leftX, $topY, $rightX, $bottomY, $borderColor, $colors[$y * $width + $x]); #$d->text('5', 'arial.ttf', 8, ($leftX+$rightX)/2, $topY, 0x000); } } $d->rotate($angle); if ($hFlip) $d->hflip(); $center = $chartWidth / 2; $radAngle = 3.1415926536 / 180 * $angle; for ($x = 0; $x < $width; ++$x) { for ($y = 0; $y < $width; ++$y) { $dx = $margin + $cellWidth * ($x + 0.5) - $center; $dy = $margin + $cellWidth * ($y + 0.5) - $center; $midX = $dx * cos($radAngle) + $dy * sin($radAngle) + $center; $midY = -$dx * sin($radAngle) + $dy * cos($radAngle) + $center; if ($hFlip) $midX = $chartWidth - $midX; $t = $d->text3($y * $width + $x, "arial.ttf", 7)->draw($midX, $midY, 0x000000, Center); } } # #clip to a circle # $mask = new DrawArea(); $mask->setSize($chartWidth, $chartWidth, Transparent); $radius = $cellWidth * $width / 2; $mask->circle($margin + $radius, $margin + $radius, $radius, $radius, 0x000000, Transparent); $mask->fill(0, 0, 0xffffff); $d = $c->makeChart3(); $d->merge($mask, 0, 0, TopLeft, 0); #rotated arrows $arrowSize = ($radius + $margin) * 4 / 10; $c2 = new XYChart($arrowSize, $arrowSize, Transparent); $c2->setPlotArea(2, 2, $arrowSize - 4, $arrowSize - 4, -1, -1, Transparent, Transparent); $c2->xAxis->setLinearScale(0, 100, NoValue); $c2->xAxis->setColors(Transparent, Transparent); $c2->yAxis->setLinearScale(0, 100, NoValue); $c2->yAxis->setColors(Transparent, Transparent); $layer = $c2->addVectorLayer(array(50), array(50), array(50), array(($hFlip ? -1 : 1) * (90 - $angle)), XAxisScale, 0xcc0000); $layer->setLineWidth(2); $layer->setArrowHead(15); $layer = $c2->addVectorLayer(array(50), array(50), array(50), array(($hFlip ? -1 : 1) * (-$angle)), XAxisScale, 0x00cc00); $layer->setLineWidth(2); $layer->setArrowHead(15); $d->merge($c2->makeChart3(), 0, $c->getHeight() - 1, BottomLeft, 0); #output the chart using the WebChartViewer $viewer = new WebChartViewer("chart1"); #output the chart $chartQuery = $c->makeSession($viewer->getId()); #set the chart URL to the viewer $viewer->setImageUrl("getchart.php?".$chartQuery); #output Javascript chart model to the browser to support mouse events $viewer->setChartModel($c->getJsChartModel()); ?> renderHTML()?>