PHP plot ECG Shape Curve Statistical Chart [Source Code]

Source: Internet
Author: User

Let's take a look at the final effect:

The following is the PHP code:

 

 
 
  1. /******************************
  2. * Line chart generation function
  3. ******************************/
  4. Function line_stats_pic ($ value_y, $ width, $ high, $ strong = 1, $ fix = 0 ){
  5. // Y value processing function
  6. Function line_point_y ($ num, $ width, $ high, $ max_num_add, $ min_num_add, $ y_pxdensity ){
  7. $ Return = $ high-floor ($ num-$ min_num_add + $ y_pxdensity)/($ max_num_add-$ min_num_add)/$ high ));
  8. Return $ return;
  9. }
  10.  
  11. // Parameter Processing
  12. $ Allnum = sizeof ($ value_y );
  13. $ Maxmax_num = max ($ value_y); // maximum value
  14. $ Minmin_num = min ($ value_y); // minimum value
  15. $ Limit_m = $ max_num-$ min_num; // very short
  16. $ Max_num_add = $ max_num + $ limit_m * 0.1; // maximum value of the Axis
  17. $ Min_num_add = $ min_num-$ limit_m * 0.1; // minimum value of the Axis
  18. $ Limit = $ max_num_add-$ min_num_add; // range-coordinate axis y
  19. $ Y_pxdensity = ($ max_num_add-$ min_num_add)/$ high; // y axis Density
  20. $ X_pxdensity = floor ($ width/$ allnum); // X axis Density
  21. Reset ($ value_y); // returns the array pointer to zero.
  22. $ I = 0;
  23. Foreach ($ value_y as $ val ){
  24. $ Point_y [$ I] = line_point_y ($ val, $ width, $ high, $ max_num_add, $ min_num_add, $ y_pxdensity );
  25. $ I ++;
  26. }
  27. $ Zero_y = line_point_y (0, $ width, $ high, $ max_num_add, $ min_num_add, $ y_pxdensity); // The y value of the zero point
  28. $ Empty_size_x = (strlen ($ max_num)> strlen ($ min_num )? Strlen ($ max_num): strlen ($ min_num) * 5 + 3; // left blank
  29.  
  30. // Starts the image stream
  31. Header ("Content-type: image/png ");
  32. $ Pic = imagecreate ($ width + $ empty_size_x + 10, $ high + 13 );
  33. Imagecolorallocate ($ pic, 255,255,255); // background color
  34. $ Color_1 = imagecolorallocate ($ pic, 30,144,255); // line color
  35. $ Color_2 = imagecolorallocate ($ pic, 0, 0); // black
  36. $ Color_3 = imagecolorallocate ($ pic, 194,194,194); // gray
  37. // Draw a grid
  38. Imagesetthickness ($ pic, 1); // mesh width
  39. $ Y_line_width = floor ($ width/100); // number of vertical gridlines
  40. $ Y_line_density = $ y_line_width = 0? 0: floor ($ width/$ y_line_width); // The vertical gridline density.
  41. $ Point_zero_y = $ zero_y> $ high? $ High: $ zero_y;
  42. Imagestring ($ pic, 1, $ empty_size_x-1, $ high + 4, "0", $ color_2); // zero axis marker
  43. For ($ I = 1; $ I <= $ y_line_width; $ I ++) {// draw vertical gridlines
  44. Imagesetthickness ($ pic, 1); // mesh width
  45. Imageline ($ pic, $ y_line_density * $ I + $ empty_size_x, 0, $ y_line_density * $ I + $ empty_size_x, $ high, $ color_3 );
  46. Imagesetthickness ($ pic, 2); // axis width
  47. Imageline ($ pic, $ y_line_density * $ I + $ empty_size_x, $ point_zero_y-4, $ y_line_density * $ I + $ empty_size_x, $ point_zero_y, $ color_2 );
  48. Imagestring ($ pic, 1, 10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.