Based on GD library and jpgraph Library
Note: For specific usage of the jpgraph class library, refer to the documentation on the official website:Http://jpgraph.net/download/manuals/classref/index.html
ForCode, The jpgraph file paths may be different. I introduced them according to the path where my own files are stored. You can change it on your own
1. Use the column chart to calculate the monthly sales volume
<? PHP /* For specific use of the jpgraph class library, please refer to the official documentation: http://jpgraph.net/download/manuals/classref/index.html */ /* * *************************** Use the column chart to calculate the monthly sales volume ******* ****************** */ Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph. php" ); Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph_bar.php "); // Reference the file where the column chart object is located $ Datay = Array (160,180,203,289,405,488,489,408,299,166,187,105 ); // Define an array $ Graph = New Graph (600,300, "Auto "); // Create a canvas-support the jpgraph Library $ Graph -> Setscale ("textlin" ); $ Graph -> Yaxis-> Scale-> setgrace (20 ); $ Graph -> Setshadow (); // Create a canvas shadow // set the position of the canvas where the Statistical Chart is located. The left margin is 40, the right margin is 30, the top margin is 30, and the bottom margin is 40, in pixels. $ Graph -> IMG-> setmargin (, ); $ Bplot = New Barplot ( $ Datay );// Create a rectangle object $ Bplot -> Setfillcolor ('Orange '); // Set the color of the column chart $ Bplot -> Value-> show (); // Set display number $ Bplot -> Value-> setformat ('% D '); // Display formatted book sales in the column chart $ Graph -> Add ( $ Bplot ); // Add a rectangle to an image $ Graph -> Setmargincolor ("lightblue "); // Set the canvas background color to light blue $ Graph -> Title-> set ("<PHP for introduction 2009> annual sales statistics "); // Create a title // set the X axis coordinate text $ = Array ("May", "may ", "August October", "August November", "August December" ); $ Graph -> Xaxis-> setticklabels ( $ ); // Set X axis $ Graph -> Title-> setfont (ff_simsun ); // Set title Font $ Graph -> Xaxis-> setfont (ff_simsun ); // Set the font of the X axis $ Graph -> Stroke (); // Output Image ?>
View code2. Use the line chart to calculate the monthly sales volume
<? PHP /* *************************** Use the line chart to calculate the monthly sales volume ********* ********************* */ Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph. php" ); Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph_line.php "); // Reference line chart lineplot class file // define an array $ Datay = Array (8320,9360, 14956,17028, 13060,15376, 25428,16216, 28548,18632, 22724,28460) ); $ Graph =New Graph (600,300, "Auto" ); // Set the position of the canvas where the Statistical Chart is located. The left margin is 50, the right margin is 40, the top margin is 30, and the bottom margin is 40, in pixels. $ Graph -> IMG-> setmargin (50, 40, 30, 40 ); $ Graph -> IMG-> setantialiasing (); // Set the smooth state of a line $ Graph -> Setscale ("textlin "); // Set scale Style $ Graph -> Setshadow ();// Create canvas shadow $ Graph -> Title-> set ("<PHP for introduction 2009> annual sales statistics "); // Set title $ Graph -> Title-> setfont (ff_simsun, fs_bold ); // Set title Font $ Graph -> Setmargincolor ("lightblue "); // Set the canvas background color to light blue $ Graph -> Yaxis-> title-> setfont (ff_simsun, fs_bold );// Set the font of the Y axis title $ Graph -> Xaxis-> setpos ("min "); // $ Graph -> Yaxis-> Hidezerolabel (); $ Graph -> Ygrid-> setfill ( True , '# EFEFEF@0.5', '# BBCCFF@0.5' ); // X axis $ = Array ("May", "may ", "August October", "August November", "August December"); $ Graph -> Xaxis-> setticklabels ( $ ); // Set X axis $ Graph -> Xaxis-> setfont (ff_simsun ); // Set the font of X axis $ Graph -> Yscale-> setgrace (20 ); $ P1 = New Lineplot ( $ Datay ); // Create a line chart object $ P1 -> Mark-> Settype (Mark_filledcircle ); // Set coordinates to circle $ P1 -> Mark-> setfillcolor ("red "); // Set fill color $ P1 -> Mark-> setwidth (4 ); // Set the diameter of the circular mark to 4 pixels $ P1 -> Setcolor ("blue "); // Set the line color to blue $ P1 -> Setcenter (); // Draw a line at the center of coordinate points on the X axis $ Graph -> Add ( $ P1 ); // Draw a line on a Statistical Chart $ Graph -> Stroke (); // Output Image ?>
View code3. Use pie charts to calculate monthly sales volume
<? PHP /* ************************ Use a 3D pie chart for statistics ********** **************** */ Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph. php" ); Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph_pie.php" ); // Reference the class file of the 3D pie chart pieplot3d object Include ("D:/php_config/jpgraph-3.5.0b1/src/jpgraph_pie3d.php" ); // Define an array $ Data = Array (266036,295621, 335851,252136, 252134,685425 ); $ Graph = New Piegraph (540,260, 'auto '); // Create canvas $ Graph -> Setshadow (); // Set canvas shadow // create a title $ Graph -> Title-> set ("<PHP for introduction 2009> annual sales statistics-3 dpie" ); $ Graph -> Title-> setfont (ff_simsun, fs_bold ); // Set title Font $ Graph -> Legend-> setfont (ff_simsun, fs_normal ); // Set legend font $ P1 = New Pieplot3d ( $ Data ); // Create a 3D pie chart object $ P1 -> Setlegends ( Array ("It", "appliance", "Daily", "clothing", "health", "food")); $ Targ = Array ("D:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 1 "," d:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 2 "," d:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 3 "," d:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 4 "," d:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 5 "," d:/php_config/jpgraph-3.5.0b1/src/examples/pie3d_csimex1.php? V = 6" ); $ ALTs = Array ("Val = % d", "Val = % d ", "Val = % d" ); $ P1 -> Setcsimtargets ($ Targ , $ ALTs ); $ P1 -> Setcenter (0.4, 0.5 ); // Set the position of the pie chart canvas $ Graph -> Add ( $ P1 ); // Add a 3D pie chart to the image $ Graph -> Strokecsim (); // Output the image to the browser ?>
View code