PHP generates a circular graph program. do you have any php circular graph generation program?
Reply to discussion (solution)
Do you want to generate an image or display it on a webpage?
You can use js chart plug-ins such as jqPlot and Highcharts for display only on the webpage.
To generate an image, you can use jpGraph. I wonder if there are styles that support your needs
It is not difficult to write it by yourself, that is, there is a large amount of computing for segment loops.
Php only provides data when running on the server. js is required for icon display, as mentioned above.
You are talking about the PHP program! I have done something similar to yours! Here is a reference... program for your reference only!
// Fill in the chart parameters
$ ChartDiameter = 140; // Chart diameter
$ ChartData = array (20, 80); // used to generate chart data. it can be obtained through the database or multiple can match the color array.
$ Msg = '000000 ';
// Converts degrees to radians
Function radians ($ degrees ){
Return ($ degrees * (pi ()/180.0 ));
}
// Obtain the value of x and y on the circle (0, 0) with the center of the circle
Function circle_point ($ degrees, $ diameter ){
$ X = cos (radians ($ degrees) * ($ diameter/2 );
$ Y = sin (radians ($ degrees) * ($ diameter/2 );
Return array ($ x, $ y );
}
// Determine the image size
$ ChartWidth = $ ChartDiameter + 22;
$ ChartHeight = $ ChartDiameter + 56;
// Determine the total number of statistics
$ ChartTotal = '';
For ($ index = 0; $ index <count ($ ChartData); $ index ++ ){
$ ChartTotal + = $ ChartData [$ index];
}
$ ChartCenterX = $ ChartDiameter/2 + 11;
$ ChartCenterY = $ ChartDiameter/2 + 28;
// Generate a blank image
$ Image = imagecreatetruecolor ($ ChartWidth, $ ChartHeight );
// Assign color
$ ColorBody = imagecolorallocate ($ image, 255,255,255); // White
$ ColorBorder = imagecolorallocate ($ image, 0, 0 );
$ ColorText = imagecolorallocate ($ image, 0, 0, 0 );
$ ColorSlice [] = imagecolorallocate ($ image, 255,255,255); // The color corresponding to the array you wrote above
$ ColorSlice [] = imagecolorallocate ($ image, 241,120,129); // background color displayed after data completion
// $ ColorSlice [] = imagecolorallocate ($ image, 0); // background color displayed after data completion
// Fill in the background
Imagefill ($ image, 0, 0, $ colorBody );
// Draw each slice
$ Degrees = 0;
For ($ index = 0; $ index <count ($ ChartData); $ index ++ ){
$ StartDegrees = round ($ Degrees );
$ Degrees + = ($ ChartData [$ index]/$ ChartTotal) * 360 );
$ EndDegrees = round ($ Degrees );
$ CurrentColor = $ colorSlice [$ index % (count ($ colorSlice)];
// Drawing F
Imagearc
($ Image, $ ChartCenterX, $ ChartCenterY, $ ChartDiameter, $ ChartDiameter, $ startDegrees, $ EndDegrees,
$ CurrentColor );
// Draw a straight line
List ($ ArcX, $ ArcY) = circle_point ($ startDegrees, $ ChartDiameter );
Imageline ($ image, $ ChartCenterX, $ ChartCenterY, floor ($ ChartCenterX + $ ArcX ),
Floor ($ ChartCenterY + $ ArcY), $ CurrentColor );
// Draw a straight line
List ($ ArcX, $ ArcY) = circle_point ($ EndDegrees, $ ChartDiameter );
Imageline ($ image, $ ChartCenterX, $ ChartCenterY, ceil ($ ChartCenterX + $ ArcX ),
Ceil ($ ChartCenterY + $ ArcY), $ CurrentColor );
// Fill the slice
$ Tempnum = $ EndDegrees-$ startDegrees;
$ MidPoint = round ($ tempnum/2) + $ startDegrees );
List ($ ArcX, $ ArcY) = circle_point ($ MidPoint, $ ChartDiameter/2 );
Imagefilltoborder ($ image, floor ($ ChartCenterX + $ ArcX), floor ($ ChartCenterY + $ ArcY ),
$ CurrentColor, $ CurrentColor );
}
$ Red = imagecolorallocate ($ image, 255, 0, 0); // red
$ White = imagecolorallocate ($ image, 255,255,255); // white
Imagefilledellipse ($ image, 81,98, 120,120, $ red );
$ Font = 'simhei. ttf ';
Imagettftext ($ image, 20, 0, 63,108, $ white, $ font, $ msg );
// An image is generated here and sent to the browser. it is important to send the header to the browser so that it is a GIF file.
Header ("Content-type: image/png ");
Imagegif ($ image );
Imagedestroy ($ image );
?>
I want to download a simhei. ttf font file!
Also, the figure you mentioned controls the drawing radius and the starting point of each slice. you need to think about the algorithm!
The problem has been solved. thank you.