ZHLineChartView.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // ZHLineChartView.h
  3. // ZHLineChart
  4. //
  5. // Created by 周亚楠 on 2020/3/1.
  6. // Copyright © 2020 Zhou. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. /**
  10. * HEX 16进制 设置颜色
  11. */
  12. #define KBaseSetHEXColor(rgbValue,al) ([UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(al)])
  13. #define KSetHEXColorWithAlpha(rgbValue,al) KBaseSetHEXColor(rgbValue,al)
  14. #define KSetHEXColor(rgbValue) KBaseSetHEXColor(rgbValue,1)
  15. #define KHorizontalLineColor KSetHEXColor(0xe8e8e8)
  16. #define KTextColor KSetHEXColor(0x666666)
  17. #define KLineColor KSetHEXColor(0x428eda)
  18. #define KHorizontalBottomLineColor KSetHEXColor(0x428eda)
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface ZHLineChartView : UIView
  21. /** 折线关键点用来显示的数据 */
  22. @property (nonatomic, strong) NSArray <NSNumber *> *lineDataAry;
  23. /** 底部横向显示文字 */
  24. @property (nonatomic, strong) NSArray <NSString *> *horizontalDataArr;
  25. /** 纵轴最大值 */
  26. @property (nonatomic, strong) NSNumber *max;
  27. /** 纵轴最小值 */
  28. @property (nonatomic, strong) NSNumber *min;
  29. /** Y轴分割个数*/
  30. @property (nonatomic, assign) NSUInteger splitCount;
  31. /** 关键点圆半径(默认3) */
  32. @property (nonatomic, assign) CGFloat circleRadius;
  33. /** 折线宽(默认1.5) */
  34. @property (nonatomic, assign) CGFloat lineWidth;
  35. /** 横向分割线宽(默认0.5) */
  36. @property (nonatomic, assign) CGFloat horizontalLineWidth;
  37. /** 底部横向分割线宽(默认1) */
  38. @property (nonatomic, assign) CGFloat horizontalBottomLineWidth;
  39. /** 关键点数据文本显示宽度(默认为文本值的宽) */
  40. @property (nonatomic, assign) CGFloat dataTextWidth;
  41. /** 纵轴文本显示宽度(默认为传入最大值max的宽) */
  42. @property (nonatomic, assign) CGFloat leftTextWidth;
  43. /** 刻度上下偏移(默认0) */
  44. @property (nonatomic, assign) CGFloat scaleOffset;
  45. /** 底部文本上下偏移(默认20) */
  46. @property (nonatomic, assign) CGFloat bottomOffset;
  47. /** 横向分割线距离左边文本偏移距离(默认5) */
  48. @property (nonatomic, assign) CGFloat lineToLeftOffset;
  49. /** 底部文本旋转角度(默认M_PI * 1.75) */
  50. @property (nonatomic, assign) CGFloat angle;
  51. /** 文本字号(默认10) */
  52. @property (nonatomic, assign) CGFloat textFontSize;
  53. /** 边界(默认UIEdgeInsetsMake(25, 5, 40, 15)) */
  54. @property (nonatomic, assign) UIEdgeInsets edge;
  55. /** 关键点边框颜色(默认0x428eda) */
  56. @property (nonatomic, strong) UIColor *circleStrokeColor;
  57. /** 关键点填充颜色(默认whiteColor) */
  58. @property (nonatomic, strong) UIColor *circleFillColor;
  59. /** 纵向横向显示文本颜色(默认0x666666) */
  60. @property (nonatomic, strong) UIColor *textColor;
  61. /** 关键点文本颜色(默认0x428eda) */
  62. @property (nonatomic, strong) UIColor *dataTextColor;
  63. /** 折线颜色(默认0x428eda) */
  64. @property (nonatomic, strong) UIColor *lineColor;
  65. /** 横向分割线颜色(默认0xe8e8e8) */
  66. @property (nonatomic, strong) UIColor *horizontalLineColor;
  67. /** 底部横向分割线颜色(默认0x428eda) */
  68. @property (nonatomic, strong) UIColor *horizontalBottomLineColor;
  69. /** 是否只显示X轴头尾,无需显示的文本赋空值可达到同样效果(默认NO,也就是全部显示)(by vitasapple)*/
  70. @property (nonatomic, assign) BOOL isShowHeadTail;
  71. /** 贝塞尔曲线绘制,增加曲度控制(默认YES) */
  72. @property (nonatomic, assign) BOOL addCurve;
  73. /** 关键点居中显示(默认YES) */
  74. @property (nonatomic, assign) BOOL toCenter;
  75. /** toCenter=YES时是否补充前后显示(默认NO) */
  76. @property (nonatomic, assign) BOOL supplement;
  77. /** 折线关键点数据是否显示(默认YES) */
  78. @property (nonatomic, assign) BOOL showLineData;
  79. /** 是否填充颜色渐变(默认YES) */
  80. @property (nonatomic, assign) BOOL showColorGradient;
  81. /** 渐变颜色集合 (默认0.4 0x428eda + 0.1 whiteColor)*/
  82. @property (nonatomic, strong) NSArray *colorArr;
  83. /**
  84. * 渲染折线图(传参后调用才会生效)
  85. */
  86. - (void)drawLineChart;
  87. @end
  88. @interface UIBezierPath (ThroughPointsBezier)
  89. /**
  90. * 曲线的弯曲水平。优值区间约为0.6 ~ 0.8。默认值和推荐值是0.7。
  91. */
  92. @property (nonatomic) CGFloat contractionFactor;
  93. /**
  94. * 正常折线绘制
  95. * 必须将CGPoint结构体包装成NSValue对象并且至少一个点来画折线。
  96. */
  97. - (void)addNormalBezierThroughPoints:(NSArray *)pointArray;
  98. /**
  99. * 三次贝塞尔曲线绘制折线
  100. * 必须将CGPoint结构体包装成NSValue对象并且至少一个点来画曲线。
  101. */
  102. - (void)addBezierThroughPoints:(NSArray *)pointArray;
  103. @end
  104. NS_ASSUME_NONNULL_END