publicclassCandleChartDataEntry:ChartDataEntry{/// shadow-high value// 最高值publicvarhigh=Double(0.0)/// shadow-low value// 最低值publicvarlow=Double(0.0)/// close value// 收盘值publicvarclose=Double(0.0)/// open value// 开盘值publicvaropen=Double(0.0)publicinit(xIndex:Int,shadowH:Double,shadowL:Double,open:Double,close:Double){super.init(value:(shadowH+shadowL)/2.0,xIndex:xIndex)self.high=shadowHself.low=shadowLself.open=openself.close=close}publicinit(xIndex:Int,shadowH:Double,shadowL:Double,open:Double,close:Double,data:AnyObject?){super.init(value:(shadowH+shadowL)/2.0,xIndex:xIndex,data:data)self.high=shadowHself.low=shadowLself.open=openself.close=close}/// Returns the overall range (difference) between shadow-high and shadow-low.// 最高值和最低值差值publicvarshadowRange:Double{returnabs(high-low)}/// Returns the body size (difference between open and close).// 开盘与收盘值 之差publicvarbodyRange:Double{returnabs(open-close)}/// the center value of the candle. (Middle value between high and low)// 高低盘中心publicoverridevarvalue:Double{get{returnsuper.value}set{super.value=(high+low)/2.0}}// MARK: NSCopyingpublicoverridefunccopyWithZone(zone:NSZone)->AnyObject{varcopy=super.copyWithZone(zone)as!CandleChartDataEntrycopy.high=highcopy.high=lowcopy.high=opencopy.high=closereturncopy}}
CandleChartDataSet
publicclassCandleChartDataSet:LineScatterCandleChartDataSet{/// the width of the candle-shadow-line in pixels./// :default: 3.0// 高低盘值的宽度publicvarshadowWidth=CGFloat(1.5)/// the space between the candle entries/// :default: 0.1 (10%)// 两个条目之间的距离privatevar_bodySpace=CGFloat(0.1)/// the color of the shadow line/// 阴影颜色publicvarshadowColor:UIColor?/// use candle color for the shadow// 是否使用 蜡烛图的颜色作为阴影颜色publicvarshadowColorSameAsCandle=false/// color for open <= close// 跌盘的颜色publicvardecreasingColor:UIColor?/// color for open > close// 涨盘的颜色publicvarincreasingColor:UIColor?/// Are decreasing values drawn as filled?// 跌盘是否填充publicvardecreasingFilled=false/// Are increasing values drawn as filled?// 涨盘是否填充publicvarincreasingFilled=truepublicoverrideinit(yVals:[ChartDataEntry]?,label:String?){super.init(yVals:yVals,label:label)}internaloverridefunccalcMinMax(#start:Int,end:Int){if(yVals.count==0){return}varentries=yValsas![CandleChartDataEntry]varendValue:Intifend==0{endValue=entries.count-1}else{endValue=end}_lastStart=start_lastEnd=end_yMin=entries[start].low_yMax=entries[start].highfor(vari=start+1;i<=endValue;i++){vare=entries[i]if(e.low<_yMin){_yMin=e.low}if(e.high>_yMax){_yMax=e.high}}}/// the space that is left out on the left and right side of each candle,/// :default: 0.1 (10%), max 0.45, min 0.0publicvarbodySpace:CGFloat{set{_bodySpace=newValueif(_bodySpace<0.0){_bodySpace=0.0}if(_bodySpace>0.45){_bodySpace=0.45}}get{return_bodySpace}}/// Is the shadow color same as the candle color?publicvarisShadowColorSameAsCandle:Bool{returnshadowColorSameAsCandle}/// Are increasing values drawn as filled?publicvarisIncreasingFilled:Bool{returnincreasingFilled;}/// Are decreasing values drawn as filled?publicvarisDecreasingFilled:Bool{returndecreasingFilled;}}