I have found an example of a simple line graph
PHP:
1.<?php
2.
3.class ImagickLineGraph extends ImagickDraw
4.{
5. /* Maximum value in the graph */
6. public $maxValue = 0;
7.
8. /* Graph data */
9. private $values;
10.
11. /* how large steps to take on the y axis values */
12. private $yValueStep;
13. private $yStepPixels;
14.
15. /* The canvas to draw the graph on*/
16. private $canvas;
17.
18. /* Amount of steps on the left hand side */
19. private $amount;
20.
21. /* The size of the graph viewport */
22. private $viewPortSize;
23.
24. public function __construct( array $values )
25. {
26. /* Loop trough values and find the max value */
27. foreach ( $values as $key => $value )
28. {
29. if ( $value['value']> $this->maxValue )
30. {
31. $this->maxValue = $value['value'];
32. }
33. }
34.
35. /* Set the values into a property */
36. $this->values = $values;
37.
38. /* How large steps to take on the left hand side values */
39. $this->yValueStep = 20;
40. $this->yStepPixels = 20;
41.
42. /* Create the horizontal lines */
43. $this->createHorizontalLines();
44.
45. /* Create the captions for the values */
46. $this->createCaptions();
47.
48. /* Create the polyline that represents the values */
49. $this->createGraphLine();
50. }
51.
52. private function createHorizontalLines()
53. {
54. /* The amount of vertical lines to draw */
55. $this->amount = ceil( $this->maxValue / $this->yValueStep );
56.
57. /* Use zero based origo but render it a bit lower */
58. $this->translate( 0, 20 );
59.
60. /* Set the viewport */
61. $this->viewPortSize = $this->amount * $this->yStepPixels;
62.
63. /* Loop trough the amount of values.. */
64. for ( $i = 0 ; $i <= $this->amount; $i++ )
65. {
66. /* Y position on the image */
67. $yPos = $this->yStepPixels * $i;
68.
69. /* Draw a horizontal line*/
70. $this->line( 50, $yPos, 490, $yPos );
71.
72. /* Create line for this value */
73. $this->annotation( 20, $this->viewPortSize - $yPos, $yPos );
74. }
75. }
76.
77. private function createCaptions()
78. {
79. /* Store the line coordinates to this array */
80. $this->polylineCoordinates = array();
81.
82. $xStep = 500 / count( $this->values );
83.
84. /* Temporary imagick object to use to get font metrics */
85. $im = new Imagick();
86.
87. /* Loop trough values.. */
88. foreach ( $this->values as $key => $value )
89. {
90. /* The position for the vertical lines */
91. $pos = 50 + ( $xStep * $key ) + 30;
92.
93. /* Query the text properties for the caption */
94. $properties = $im->queryFontMetrics( $this, $value['caption'] );
95.
96. /* Place the text in the middle of the vertical line */
97. $tPos = $pos - ( $properties['textWidth'] / 2 );
98.
99. /* Write the caption, one step below the actual graph */
100. $this->annotation( $tPos,
101. ( $this->amount * $this->yStepPixels ) + $this->yStepPixels,
102. $value['caption'] );
103.
104. /* Draw the vertical line for this value */
105. $this->line( $pos, $this->amount * $this->yStepPixels, $pos, 0 );
106.
107. /* Set the polyline coordinate for this line */
108. $this->polylineCoordinates[$key]['x'] = $pos ;
109.
110. /* And the Y coordinate */
111. $this->polylineCoordinates[$key]['y'] =
112. $this->viewPortSize - $value['value'];
113. }
114.
115. }
116.
117. function createGraphLine()
118. {
119. /* Use transparent fill, otherwise polyline is filled with black */
120. $this->setFillColor( new ImagickPixel( "transparent" ) );
121.
122. /* Stroke the polyline with red color*/
123. $this->setStrokeColor( new ImagickPixel( "red" ) );
124.
125. /* Antialias the line */
126. $this->setStrokeAntialias( true );
127.
128. /* Draw the polyline from the coordinates */
129. $this->polyLine( $this->polylineCoordinates );
130. }
131.}
132./* values to show in the graph */
133.$values = array (
134. array( "caption" => "Random", "value" => 202.54 ),
135. array( "caption" => "Random again", "value" => 34.2 ),
136. array( "caption" => "Something", "value" => 59.5 ),
137. array( "caption" => "Test", "value" => 210.34 ),
138. array( "caption" => "Sporks", "value" => 110.34 ),
139. );
140.try
141.{
142. /* Create a new graph */
143. $graph = new ImagickLineGraph( $values );
144.
145. /* Initialize the canvas */
146. $canvas = new Imagick();
147.
148. /* Create empty image */
149. $canvas->newImage( 500, $graph->maxValue + 150,
150. new ImagickPixel( "white" ) );
151.
152. /* Set the image format to png */
153. $canvas->setImageFormat( "png" );
154.
155. /* Render the graph on the canvas */
156. $canvas->drawImage( $graph );
157.
158.}
159.catch ( Exception $e )
160.{
161. echo $e->getMessage();
162. die();
163.}
164.header( "Content-Type: image/png" );
165.echo $canvas;
166.
167.?>
Maybe it can help you. But I'm sure you need learn many
php tutorials to get what you want