蜡烛图


  • CandleChartDataEntry 蜡烛图 数据条目
  • CandleChartDataSet 蜡烛图集合
  • CandleChartData 蜡烛图数据

CandleChartDataEntry


public class CandleChartDataEntry: ChartDataEntry
{
/// shadow-high value
// 最高值
public var high = Double(0.0)

/// shadow-low value
// 最低值
public var low = Double(0.0)

/// close value
// 收盘值
public var close = Double(0.0)

/// open value
// 开盘值
public var open = Double(0.0)

public init(xIndex: Int, shadowH: Double, shadowL: Double, open: Double, close: Double)
{
super.init(value: (shadowH + shadowL) / 2.0, xIndex: xIndex)

self.high = shadowH
self.low = shadowL
self.open = open
self.close = close
}

public init(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 = shadowH
self.low = shadowL
self.open = open
self.close = close
}

/// Returns the overall range (difference) between shadow-high and shadow-low.
// 最高值和最低值差值
public var shadowRange: Double
{
return abs(high - low)
}

/// Returns the body size (difference between open and close).
// 开盘与收盘值 之差
public var bodyRange: Double
{
return abs(open - close)
}

/// the center value of the candle. (Middle value between high and low)
// 高低盘中心
public override var value: Double
{
get
{
return super.value
}
set
{
super.value = (high + low) / 2.0
}
}

// MARK: NSCopying

public override func copyWithZone(zone: NSZone) -> AnyObject
{
var copy = super.copyWithZone(zone) as! CandleChartDataEntry
copy.high = high
copy.high = low
copy.high = open
copy.high = close
return copy
}
}

CandleChartDataSet


public class CandleChartDataSet: LineScatterCandleChartDataSet
{
/// the width of the candle-shadow-line in pixels.
/// :default: 3.0
// 高低盘值的宽度
public var shadowWidth = CGFloat(1.5)

/// the space between the candle entries
/// :default: 0.1 (10%)
// 两个条目之间的距离
private var _bodySpace = CGFloat(0.1)

/// the color of the shadow line
/// 阴影颜色
public var shadowColor: UIColor?

/// use candle color for the shadow
// 是否使用 蜡烛图的颜色作为阴影颜色
public var shadowColorSameAsCandle = false

/// color for open <= close
// 跌盘的颜色
public var decreasingColor: UIColor?

/// color for open > close
// 涨盘的颜色
public var increasingColor: UIColor?

/// Are decreasing values drawn as filled?
// 跌盘是否填充
public var decreasingFilled = false

/// Are increasing values drawn as filled?
// 涨盘是否填充
public var increasingFilled = true

public override init(yVals: [ChartDataEntry]?, label: String?)
{
super.init(yVals: yVals, label: label)
}

internal override func calcMinMax(#start: Int, end: Int)
{
if (yVals.count == 0)
{
return
}

var entries = yVals as! [CandleChartDataEntry]

var endValue : Int

if end == 0
{
endValue = entries.count - 1
}
else
{
endValue = end
}

_lastStart = start
_lastEnd = end

_yMin = entries[start].low
_yMax = entries[start].high

for (var i = start + 1; i <= endValue; i++)
{
var e = 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.0
public var bodySpace: CGFloat
{
set
{
_bodySpace = newValue

if (_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?
public var isShadowColorSameAsCandle: Bool { return shadowColorSameAsCandle }

/// Are increasing values drawn as filled?
public var isIncreasingFilled: Bool { return increasingFilled; }

/// Are decreasing values drawn as filled?
public var isDecreasingFilled: Bool { return decreasingFilled; }
}

CandleChartData


public class CandleChartData: BarLineScatterCandleChartData
{
public override init()
{
super.init()
}

public override init(xVals: [String?]?, dataSets: [ChartDataSet]?)
{
super.init(xVals: xVals, dataSets: dataSets)
}

public override init(xVals: [NSObject]?, dataSets: [ChartDataSet]?)
{
super.init(xVals: xVals, dataSets: dataSets)
}
}