DepthChart 深度圖
注意:該深度圖橫坐標(biāo)是以檔位為單位衷笋,縱坐標(biāo)是以檔位數(shù)量為單位
1酣溃、實現(xiàn)代理
view.delegate = self
extension ViewController: CHKDepthChartDelegate {
/// 圖表的總條數(shù)
/// 總數(shù) = 買方 + 賣方
/// - Parameter chart:
/// - Returns:
func numberOfPointsInDepthChart(chart: CHDepthChartView) -> Int {
return self.depthDatas.count
}
/// 每個點顯示的數(shù)值項
///
/// - Parameters:
/// - chart:
/// - index:
/// - Returns:
func depthChart(chart: CHDepthChartView, valueForPointAtIndex index: Int) -> CHKDepthChartItem {
return self.depthDatas[index]
}
/// y軸以基底值建立
///
/// - Parameter depthChart:
/// - Returns:
func baseValueForYAxisInDepthChart(in depthChart: CHDepthChartView) -> Double {
return 0
}
/// y軸以基底值建立后逸月,每次段的增量
///
/// - Parameter depthChart:
/// - Returns:
func incrementValueForYAxisInDepthChart(in depthChart: CHDepthChartView) -> Double {
//計算一個顯示4個輔助線的友好效果
// var step = self.maxAmount / 4
// var j = 0
// while step / 10 > 1 {
// j += 1
// step = step / 10
// }
//
// //冪運算
// var pow: Int = 1
// if j > 0 {
// for _ in 1...j {
// pow = pow * 10
// }
// }
//
// step = Float(lroundf(step) * pow)
//
// return Double(step)
let step = Double(self.maxAmount / 4)
print("setp == \(step)")
return step
}
/// 縱坐標(biāo)值顯示間距
func widthForYAxisLabelInDepthChart(in depthChart: CHDepthChartView) -> CGFloat {
return 30
}
/// 縱坐標(biāo)值
func depthChart(chart: CHDepthChartView, labelOnYAxisForValue value: CGFloat) -> String {
if value >= 1000{
let newValue = value / 1000
return newValue.ch_toString(maxF: 0) + "K"
}else {
return value.ch_toString(maxF: 1)
}
}
/// 價格的小數(shù)位
func depthChartOfDecimal(chart: CHDepthChartView) -> Int {
return 4
}
/// 量的小數(shù)位
func depthChartOfVolDecimal(chart: CHDepthChartView) -> Int {
return 6
}
// /// 自定義點擊顯示信息view
// func depthChartShowItemView(chart: CHDepthChartView, Selected item: CHKDepthChartItem) -> UIView? {
// let view = UIView(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
// view.backgroundColor = UIColor.red
// return view
// }
// /// 點擊標(biāo)記圖
// func depthChartTagView(chart: CHDepthChartView, Selected item: CHKDepthChartItem) -> UIView? {
// let view = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
// view.backgroundColor = UIColor.blue
// return view
// }
}
2栓撞、自定義樣式
extension CHKLineChartStyle {
/// 深度圖樣式
static var depthStyle: CHKLineChartStyle = {
let style = CHKLineChartStyle()
//字體大小
style.labelFont = UIFont.systemFont(ofSize: 10)
//分區(qū)框線顏色
style.lineColor = UIColor(white: 0.7, alpha: 1)
//背景顏色
style.backgroundColor = UIColor.white
//文字顏色
style.textColor = UIColor(white: 0.5, alpha: 1)
//整個圖表的內(nèi)邊距
style.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
//Y軸是否內(nèi)嵌式
style.isInnerYAxis = false
//Y軸顯示在右邊
style.showYAxisLabel = .right
/// 買單居右
style.bidChartOnDirection = .left
//邊界寬度
style.borderWidth = (0, 0, 0, 0)
//是否允許手勢點擊
style.enableTap = true
//買方深度圖層的顏色 UIColor(hex:0xAD6569) UIColor(hex:0x469777)
style.bidColor = (UIColor(hex:0xAD6569), UIColor(hex:0xAD6569), 1)
// style.askColor = (UIColor(hex:0xAD6569), UIColor(hex:0xAD6569), 1)
//買方深度圖層的顏色
style.askColor = (UIColor(hex:0x469777), UIColor(hex:0x469777), 1)
// style.bidColor = (UIColor(hex:0x469777), UIColor(hex:0x469777), 1)
return style
}()
}