Ei kuvausta

AAChartModel.m 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // AAChartModel.m
  3. // AAChartKit
  4. //
  5. // Created by An An on 17/1/20.
  6. // Copyright © 2017年 An An. All rights reserved.
  7. //*************** ...... SOURCE CODE ...... ***************
  8. //***...................................................***
  9. //*** https://github.com/AAChartModel/AAChartKit ***
  10. //*** https://github.com/AAChartModel/AAChartKit-Swift ***
  11. //***...................................................***
  12. //*************** ...... SOURCE CODE ...... ***************
  13. /*
  14. * -------------------------------------------------------------------------------
  15. *
  16. * 🌕 🌖 🌗 🌘 ❀❀❀ WARM TIPS!!! ❀❀❀ 🌑 🌒 🌓 🌔
  17. *
  18. * Please contact me on GitHub,if there are any problems encountered in use.
  19. * GitHub Issues : https://github.com/AAChartModel/AAChartKit/issues
  20. * -------------------------------------------------------------------------------
  21. * And if you want to contribute for this project, please contact me as well
  22. * GitHub : https://github.com/AAChartModel
  23. * StackOverflow : https://stackoverflow.com/users/7842508/codeforu
  24. * JianShu : http://www.jianshu.com/u/f1e6753d4254
  25. * SegmentFault : https://segmentfault.com/u/huanghunbieguan
  26. *
  27. * -------------------------------------------------------------------------------
  28. */
  29. #import "AAChartModel.h"
  30. AAChartType const AAChartTypeColumn = @"column";
  31. AAChartType const AAChartTypeBar = @"bar";
  32. AAChartType const AAChartTypeArea = @"area";
  33. AAChartType const AAChartTypeAreaspline = @"areaspline";
  34. AAChartType const AAChartTypeLine = @"line";
  35. AAChartType const AAChartTypeSpline = @"spline";
  36. AAChartType const AAChartTypeScatter = @"scatter";
  37. AAChartType const AAChartTypePie = @"pie";
  38. AAChartType const AAChartTypeBubble = @"bubble";
  39. AAChartType const AAChartTypePyramid = @"pyramid";
  40. AAChartType const AAChartTypeFunnel = @"funnel";
  41. AAChartType const AAChartTypeColumnrange = @"columnrange";
  42. AAChartType const AAChartTypeArearange = @"arearange";
  43. AAChartType const AAChartTypeAreasplinerange = @"areasplinerange";
  44. AAChartType const AAChartTypeBoxplot = @"boxplot";
  45. AAChartType const AAChartTypeWaterfall = @"waterfall";
  46. AAChartType const AAChartTypePolygon = @"polygon";
  47. AAChartSubtitleAlignType const AAChartSubtitleAlignTypeLeft = @"left";
  48. AAChartSubtitleAlignType const AAChartSubtitleAlignTypeCenter = @"center";
  49. AAChartSubtitleAlignType const AAChartSubtitleAlignTypeRight = @"right";
  50. AAChartZoomType const AAChartZoomTypeNone = @"none";
  51. AAChartZoomType const AAChartZoomTypeX = @"x";
  52. AAChartZoomType const AAChartZoomTypeY = @"y";
  53. AAChartZoomType const AAChartZoomTypeXY = @"xy";
  54. AAChartStackingType const AAChartStackingTypeFalse = @"";
  55. AAChartStackingType const AAChartStackingTypeNormal = @"normal";
  56. AAChartStackingType const AAChartStackingTypePercent = @"percent";
  57. AAChartSymbolType const AAChartSymbolTypeCircle = @"circle";
  58. AAChartSymbolType const AAChartSymbolTypeSquare = @"square";
  59. AAChartSymbolType const AAChartSymbolTypeDiamond = @"diamond";
  60. AAChartSymbolType const AAChartSymbolTypeTriangle = @"triangle";
  61. AAChartSymbolType const AAChartSymbolTypeTriangle_down = @"triangle-down";
  62. AAChartSymbolStyleType const AAChartSymbolStyleTypeDefault = @"default";
  63. AAChartSymbolStyleType const AAChartSymbolStyleTypeInnerBlank = @"innerBlank";
  64. AAChartSymbolStyleType const AAChartSymbolStyleTypeBorderBlank = @"borderBlank";
  65. AAChartFontWeightType const AAChartFontWeightTypeThin = @"thin";
  66. AAChartFontWeightType const AAChartFontWeightTypeRegular = @"regular";
  67. AAChartFontWeightType const AAChartFontWeightTypeBold = @"bold";
  68. AALineDashSyleType const AALineDashSyleTypeSolid = @"Solid";
  69. AALineDashSyleType const AALineDashSyleTypeShortDash = @"ShortDash";
  70. AALineDashSyleType const AALineDashSyleTypeShortDot = @"ShortDot";
  71. AALineDashSyleType const AALineDashSyleTypeShortDashDot = @"ShortDashDot";
  72. AALineDashSyleType const AALineDashSyleTypeShortDashDotDot = @"ShortDashDotDot";
  73. AALineDashSyleType const AALineDashSyleTypeDot = @"Dot";
  74. AALineDashSyleType const AALineDashSyleTypeDash = @"Dash";
  75. AALineDashSyleType const AALineDashSyleTypeLongDash = @"LongDash";
  76. AALineDashSyleType const AALineDashSyleTypeDashDot = @"DashDot";
  77. AALineDashSyleType const AALineDashSyleTypeLongDashDot = @"LongDashDot";
  78. AALineDashSyleType const AALineDashSyleTypeLongDashDotDot = @"LongDashDotDot";
  79. @implementation AAChartModel
  80. - (instancetype)init {
  81. self = [super init];
  82. if (self) {
  83. _chartType = AAChartTypeColumn;//默认图表类型为柱状图
  84. _animationType = AAChartAnimationLinear;//默认使用非easing.js中的'linear'线性渐变效果
  85. _animationDuration = @800;//默认动画时长为800毫秒
  86. _subtitleAlign = AAChartSubtitleAlignTypeLeft;//默认图表副标题居左显示
  87. _stacking = AAChartStackingTypeFalse;//默认不开启图表数据的堆积效果
  88. _zoomType = AAChartZoomTypeNone ;//默认禁用图表的手势缩放功能
  89. _colorsTheme = @[@"#1e90ff",@"#ef476f",@"#ffd066",@"#04d69f",@"#25547c",];//默认颜色主题
  90. _tooltipEnabled = YES;//默认启用浮动提示框
  91. // _tooltipCrosshairs = YES;//默认启用准星线
  92. _tooltipShared = YES;//默认多组数据共享一个浮动提示框
  93. _xAxisLabelsEnabled = YES;//默认显示 X轴坐标点文字
  94. _xAxisGridLineWidth = @0; //设置x轴分割线宽度为0个像素,即是隐藏 X轴分割线
  95. _xAxisTickInterval = @1; //x轴坐标点间隔数(默认是1)
  96. _xAxisVisible = YES;//x轴默认可见
  97. _yAxisVisible = YES;//y轴默认可见
  98. _yAxisLabelsEnabled = YES;
  99. _yAxisLineWidth = @0.5; //y轴轴线的宽度为1
  100. _yAxisGridLineWidth = @1; //y轴分割线线宽为一个像素
  101. _legendEnabled = YES;//默认显示图例(图表下方可点击的带有文字的小圆点)
  102. _borderRadius = @0; //柱状图长条图头部圆角半径(可用于设置头部的形状,仅对条形图,柱状图有效,设置为1000时,柱形图或者条形图头部为楔形)
  103. _markerRadius = @5; //折线连接点的半径长度,如果值设置为0,这样就相当于不显示了
  104. _yAxisAllowDecimals = YES;//默认y轴允许显示小数
  105. _zoomResetButtonText = @"恢复缩放";//恢复缩放按钮的标题文字
  106. _titleFontColor = @"#000000";//标题字体颜色为黑色
  107. _titleFontWeight = AAChartFontWeightTypeRegular;//常规字体
  108. _titleFontSize = @11;
  109. _subtitleFontColor = @"#000000";//副标题字体颜色为黑色
  110. _subtitleFontWeight = AAChartFontWeightTypeRegular;//常规字体
  111. _subtitleFontSize = @9;
  112. _dataLabelFontColor = @"#000000";//数据标签默认颜色为黑色
  113. _dataLabelFontWeight = AAChartFontWeightTypeBold;//图表的数据字体为粗体
  114. _dataLabelFontSize = @10;
  115. _xAxisLabelsFontSize = @11;//x轴字体大小
  116. _xAxisLabelsFontColor = @"#778899";//浅石板灰色字体
  117. _xAxisLabelsFontWeight = AAChartFontWeightTypeThin;//细体字
  118. _yAxisLabelsFontSize = @11;
  119. _yAxisLabelsFontColor = @"#778899";//浅石板灰色字体
  120. _yAxisLabelsFontWeight = AAChartFontWeightTypeThin;//细体字
  121. }
  122. return self;
  123. }
  124. AAPropSetFuncImplementation(AAChartModel, NSString *, title);//标题内容
  125. AAPropSetFuncImplementation(AAChartModel, NSNumber *, titleFontSize);//Title label font size
  126. AAPropSetFuncImplementation(AAChartModel, NSString *, titleFontColor);//Title label font color
  127. AAPropSetFuncImplementation(AAChartModel, NSString *, titleFontWeight);//Title label font weight
  128. AAPropSetFuncImplementation(AAChartModel, NSString *, subtitle);//副标题内容
  129. AAPropSetFuncImplementation(AAChartModel, NSNumber *, subtitleFontSize);//Subtitle label font size
  130. AAPropSetFuncImplementation(AAChartModel, NSString *, subtitleFontColor);//Subtitle label font color
  131. AAPropSetFuncImplementation(AAChartModel, NSString *, subtitleFontWeight);//Subtitle label font weight
  132. AAPropSetFuncImplementation(AAChartModel, NSString *, backgroundColor);//图表背景色(必须为十六进制的颜色色值如红色"#FF0000")
  133. AAPropSetFuncImplementation(AAChartModel, NSArray <NSString *>*, colorsTheme);//图表主题颜色数组
  134. AAPropSetFuncImplementation(AAChartModel, NSArray <NSString *>*, categories);//x轴坐标每个点对应的名称(注意:这个不是用来设置 X 轴的值,仅仅是用于设置 X 轴文字内容的而已)
  135. AAPropSetFuncImplementation(AAChartModel, NSArray *, series);//图表的数据列内容
  136. AAPropSetFuncImplementation(AAChartModel, AAChartSubtitleAlignType, subtitleAlign);//图表副标题文本水平对齐方式。可选的值有 “left”,”center“和“right”。 默认是:center.
  137. AAPropSetFuncImplementation(AAChartModel, AAChartType, chartType);//图表类型
  138. AAPropSetFuncImplementation(AAChartModel, AAChartStackingType, stacking);//堆积样式
  139. AAPropSetFuncImplementation(AAChartModel, AAChartSymbolType, symbol);//折线曲线连接点的类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
  140. AAPropSetFuncImplementation(AAChartModel, AAChartSymbolStyleType, symbolStyle);
  141. AAPropSetFuncImplementation(AAChartModel, AAChartZoomType, zoomType);//缩放类型 AAChartZoomTypeX 表示可沿着 x 轴进行手势缩放
  142. AAPropSetFuncImplementation(AAChartModel, AAChartAnimation, animationType);//设置图表的渲染动画类型
  143. AAPropSetFuncImplementation(AAChartModel, NSNumber *, animationDuration);//设置图表的渲染动画时长(动画单位为毫秒)
  144. AAPropSetFuncImplementation(AAChartModel, BOOL, inverted);//x 轴是否垂直,默认为否
  145. AAPropSetFuncImplementation(AAChartModel, BOOL, gradientColorEnabled);//是否要为渐变色,默认为否
  146. AAPropSetFuncImplementation(AAChartModel, BOOL, polar);//是否极化图形(变为雷达图),默认为否
  147. AAPropSetFuncImplementation(AAChartModel, BOOL, dataLabelEnabled);//是否显示数据,默认为否
  148. AAPropSetFuncImplementation(AAChartModel, NSString *, dataLabelFontColor);//Datalabel font color
  149. AAPropSetFuncImplementation(AAChartModel, NSNumber *, dataLabelFontSize);//Datalabel font size
  150. AAPropSetFuncImplementation(AAChartModel, NSString *, dataLabelFontWeight);//Datalabel font weight
  151. AAPropSetFuncImplementation(AAChartModel, BOOL, xAxisVisible);//x 轴是否可见(默认可见)
  152. AAPropSetFuncImplementation(AAChartModel, BOOL, xAxisReversed);// x 轴翻转,默认为否
  153. AAPropSetFuncImplementation(AAChartModel, BOOL, xAxisLabelsEnabled);//x 轴是否显示文字
  154. AAPropSetFuncImplementation(AAChartModel, NSNumber *, xAxisLabelsFontSize);//x 轴文字字体大小
  155. AAPropSetFuncImplementation(AAChartModel, NSString *, xAxisLabelsFontColor);//x 轴文字字体颜色
  156. AAPropSetFuncImplementation(AAChartModel, AAChartFontWeightType, xAxisLabelsFontWeight);//x 轴文字字体粗细
  157. AAPropSetFuncImplementation(AAChartModel, NSNumber *, xAxisGridLineWidth);//x 轴网格线的宽度
  158. AAPropSetFuncImplementation(AAChartModel, NSNumber *, xAxisTickInterval);//x轴刻度点间隔数(设置每隔几个点显示一个 X轴的内容)
  159. AAPropSetFuncImplementation(AAChartModel, NSNumber *, xAxisCrosshairWidth);
  160. AAPropSetFuncImplementation(AAChartModel, NSString *, xAxisCrosshairColor);
  161. AAPropSetFuncImplementation(AAChartModel, AALineDashSyleType, xAxisCrosshairDashStyleType);
  162. AAPropSetFuncImplementation(AAChartModel, BOOL, yAxisVisible);//y 轴是否可见(默认可见)
  163. AAPropSetFuncImplementation(AAChartModel, BOOL, yAxisReversed);//y 轴翻转,默认为否
  164. AAPropSetFuncImplementation(AAChartModel, BOOL, yAxisLabelsEnabled);//y 轴是否显示文字
  165. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisLabelsFontSize);//y 轴文字字体大小
  166. AAPropSetFuncImplementation(AAChartModel, NSString *, yAxisLabelsFontColor);//y 轴文字字体颜色
  167. AAPropSetFuncImplementation(AAChartModel, AAChartFontWeightType , yAxisLabelsFontWeight);//y 轴文字字体粗细
  168. AAPropSetFuncImplementation(AAChartModel, NSString *, yAxisTitle);//y 轴标题
  169. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisLineWidth);//y y-axis line width
  170. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisGridLineWidth);//y轴网格线的宽度
  171. AAPropSetFuncImplementation(AAChartModel, BOOL, yAxisAllowDecimals);//是否允许 y 轴显示小数
  172. AAPropSetFuncImplementation(AAChartModel, NSArray *, yAxisPlotLines);//y 轴基线的配置
  173. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisMax);//y 轴最大值
  174. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisMin);//y 轴最小值(设置为0就不会有负数)
  175. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisTickInterval);
  176. AAPropSetFuncImplementation(AAChartModel, NSArray *, yAxisTickPositions);//自定义 y 轴坐标(如:[@(0), @(25), @(50), @(75) , (100)])
  177. AAPropSetFuncImplementation(AAChartModel, NSNumber *, yAxisCrosshairWidth);
  178. AAPropSetFuncImplementation(AAChartModel, NSString *, yAxisCrosshairColor);
  179. AAPropSetFuncImplementation(AAChartModel, AALineDashSyleType, yAxisCrosshairDashStyleType);
  180. AAPropSetFuncImplementation(AAChartModel, BOOL, tooltipEnabled);//是否显示浮动提示框(默认显示)
  181. AAPropSetFuncImplementation(AAChartModel, BOOL, tooltipShared)//是否多组数据共享一个浮动提示框
  182. AAPropSetFuncImplementation(AAChartModel, NSString *, tooltipValueSuffix);//浮动提示框单位后缀
  183. AAPropSetFuncImplementation(AAChartModel, BOOL, connectNulls);//设置折线是否断点重连(是否连接空值点)
  184. AAPropSetFuncImplementation(AAChartModel, BOOL, legendEnabled);//是否显示图例 lengend(图表底部可点按的圆点和文字)
  185. AAPropSetFuncImplementation(AAChartModel, NSNumber *, borderRadius);//柱状图长条图头部圆角半径(可用于设置头部的形状,仅对条形图,柱状图有效)
  186. AAPropSetFuncImplementation(AAChartModel, NSNumber *, markerRadius);//折线连接点的半径长度
  187. AAPropSetFuncImplementation(AAChartModel, NSString *, zoomResetButtonText); //String to display in 'zoom reset button"
  188. @end