Php code for drawing line charts
Strlen ($ min_num )? Strlen ($ max_num): strlen ($ min_num) * 5 + 3; // blank on the left // start header of the image stream ("Content-type: image/png "); $ pic = imagecreate ($ width + $ empty_size_x + 10, $ high + 13); imagecolorallocate ($ pic, 255,255,255); // background color $ color_1 = imagecolorallocate ($ pic, 30,144,255); // Line Color $ color_2 = imagecolorallocate ($ pic, 194,194,194, 0); // Black $ color_3 = imagecolorallocate ($ pic ); // Gray // draw the grid imagesetthickness ($ pic, 1); // The grid width $ y_line_width = floor ($ width/100 ); // Number of vertical gridlines $ y_line_density = $ y_line_width = 0? 0: floor ($ width/$ y_line_width); // longitudinal gridline density $ point_zero_y = $ zero_y> $ high? $ High: $ zero_y; imagestring ($ pic, 1, $ empty_size_x-1, $ high + 4, "0", $ color_2 ); // for ($ I = 1; $ I <= $ y_line_width; $ I ++) {// draw the vertical gridline imagesetthickness ($ pic, 1 ); // grid line width imageline ($ pic, $ y_line_density * $ I + $ empty_size_x, 0, $ y_line_density * $ I + $ empty_size_x, $ high, $ color_3 ); imagesetthickness ($ pic, 2); // axis point width imageline ($ pic, $ y_line_density * $ I + $ empty_size_x, $ point_zero_y-4, $ y_line_density * $ I + $ empty_size_x, $ point_z Ero_y, $ color_2); imagestring ($ pic, 1,100 * $ I + $ empty_size_x-5, $ high + 4, $ allnum/$ y_line_width * $ I, $ color_2 ); // number axis marker} $ x_line_width = floor ($ high/30); // Number of Horizontal gridlines $ x_line_density = $ x_line_width = 0? 0: floor ($ high/$ y_line_width); // horizontal gridline density if ($ zero_y> $ high) {// draw a horizontal gridline imagestring ($ pic, $ high-3, round ($ min_num_add, $ fix), $ color_2); // Mark the zero-point numeric axis for ($ I = 1; $ I <= $ x_line_width; $ I ++) {imagesetthickness ($ pic, 1); // The grid width imageline ($ pic, 0 + $ empty_size_x, $ high-$ x_line_density * $ I, $ width + $ empty_size_x, $ high-$ x_line_density * $ I, $ color_3); imagesetthickness ($ pic, 2); // imageline ($ pic, 0 + $ empty_size_x, $ high-$ x _ Line_density * $ I, 3 + $ empty_size_x, $ high-$ x_line_density * $ I, $ color_2); imagestring ($ pic, $ high-$ x_line_density * $ I-3, round ($ limit/$ x_line_width * $ I + $ min_num_add, $ fix), $ color_2); // number axis flag} else {imagestring ($ pic, 1, $ empty_size_x-8, $ zero_y, "0", $ color_2); // for ($ I = 1; $ I <= ceil ($ x_line_width/2); $ I ++) {imagesetthickness ($ pic, 1); // The grid width. imageline ($ pic, 0 + $ empty_size_x, $ zero_y-$ x_line_density * $ I, $ width + $ Empty_size_x, $ zero_y-$ x_line_density * $ I, $ color_3); if ($ zero_y + $ x_line_density * $ I <$ high) {imageline ($ pic, 0 + $ empty_size_x, $ zero_y + $ x_line_density * $ I, $ width + $ fill, $ zero_y + $ x_line_density * $ I, $ color_3);} imagesetthickness ($ pic, 2); // The axis width imageline ($ pic, 0 + $ empty_size_x, $ zero_y-$ x_line_density * $ I, 3 + $ empty_size_x, $ zero_y-$ x_line_density * $ I, $ color_2); if ($ zero_y + $ x_line_density * $ I <$ high) {im Ageline ($ pic, 0 + $ empty_size_x, $ zero_y + $ x_line_density * $ I, 3 + $ empty_size_x, $ zero_y + $ x_line_density * $ I, $ color_2 );} imagestring ($ pic, $ zero_y-$ x_line_density * $ I-3, round ($ limit/$ x_line_width * $ I, $ fix), $ color_2 ); // if ($ zero_y + $ x_line_density * $ I <$ high) {imagestring ($ pic, $ zero_y + $ x_line_density * $ I-3, round (-$ limit/$ x_line_width * $ I, $ fix), $ color_2); // number axis marker }}// draw the axis imagesetthickness ($ pic, 2 ); // Axis width imageline ($ pic, 1 + $ empty_size_x, 0, 1 + $ empty_size_x, $ high, $ color_2); if ($ zero_y> $ high) {// x axis position imageline ($ pic, 0 + $ empty_size_x, $ high, $ width + $ empty_size_x, $ high, $ color_2);} else {imageline ($ pic, 0 + $ empty_size_x, $ zero_y, $ width + $ empty_size_x, $ zero_y, $ color_2);} // Generate a line $ point_x = 0; $ j = 0; imagesetthickness ($ pic, $ strong); // line width while ($ j + 1 <$ allnum) {imageline ($ pic, $ point_x + 2 + $ empty_size_x, $ point_y [$ j], $ point _ X + $ x_pxdensity + 2 + $ empty_size_x, $ point_y [$ j + 1], $ color_1); $ point_x + = $ x_pxdensity; $ j ++ ;} imagepng ($ pic); imagedestroy ($ pic);}/* function description and example parameter description: $ value_y -------- contains the array of the line chart you want to generate, the key value must increase progressively from 0. $ Width -------- The grid width (not white) of the generated line chart $ high -------- Height $ strong ------- line width (1 by default) $ fix ------- number of data retention digits (rounded by default) */for ($ I = 0; $ I <100; $ I ++) {$ value = rand (1,200); $ value_y [] = $ value ;} line_stats_pic ($ value_y, 500,100, 1, 1);?>