美文网首页
深度图 DepthChartView

深度图 DepthChartView

作者: 晓蜻蜓 | 来源:发表于2018-05-25 17:20 被阅读0次

DepthChart 深度图

注意:该深度图横坐标是以档位为单位,纵坐标是以档位数量为单位

源码

2018-05-25 16_43_00.gif

1、实现代理

view.delegate = self

extension ViewController: CHKDepthChartDelegate {
    
    
    /// 图表的总条数
    /// 总数 = 买方 + 卖方
    /// - Parameter chart:
    /// - Returns:
    func numberOfPointsInDepthChart(chart: CHDepthChartView) -> Int {
        return self.depthDatas.count
    }
    
    
    /// 每个点显示的数值项
    ///
    /// - 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
    }
    /// 纵坐标值显示间距
    func widthForYAxisLabelInDepthChart(in depthChart: CHDepthChartView) -> CGFloat {
        return 30
    }
    /// 纵坐标值
    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)
        }
    }
    
    /// 价格的小数位
    func depthChartOfDecimal(chart: CHDepthChartView) -> Int {
        return 4
    }
    
    /// 量的小数位
    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
    //    }
    //    /// 点击标记图
    //    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)
        //分区框线颜色
        style.lineColor = UIColor(white: 0.7, alpha: 1)
        //背景颜色
        style.backgroundColor = UIColor.white
        //文字颜色
        style.textColor = UIColor(white: 0.5, alpha: 1)
        //整个图表的内边距
        style.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        //Y轴是否内嵌式
        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
        
    }()
}

该项目属于二次开发,基于一个swiftK线 项目开发

项目地址

相关文章

  • 深度图 DepthChartView

    DepthChart 深度图 注意:该深度图横坐标是以档位为单位,纵坐标是以档位数量为单位 源码 1、实现代理 v...

  • Unity Shader - 深度图基础及应用

    文章内容 深度图基础 访问深度图 利用深度图重建世界坐标 深度图应用渲染深度图相交高亮能量场全局雾效扫描线水淹垂直...

  • Kinect学习——关于

    针对Kinect深度图仍然有残缺的问题,希望能通过对应的彩色图修复残缺深度图。由于Kinect 2的深度图和彩色图...

  • Halcon绘制彩色深度图

    此小文主要介绍颜色空间的转换,将深度图转为彩色,借以说明颜色转换与图像通道,下面是效果: 深度图的生成 深度图的生...

  • RGB-D(深度图像) & 图像深度

    RGB-D(深度图像) 深度图像 = 普通的RGB三通道彩色图像 + Depth Map   在3D计算机...

  • 3维数据表达

    RGB-D(深度图像) 深度图像 = 普通的RGB三通道彩色图像+Depth MapRGB-D图像其实是两幅图像,...

  • Unity Shader - 深度图基础及应用(转)

    Unity Shader - 深度图基础及应用 最近看了一些关于深度图及应用的文章,这篇是写的比较完整的,另外在u...

  • Robust Face Recognition with Dee

    #简介 深度信息对人脸识别提供了有用的帮助 .但是由于深度图噪音,姿态和表情变化等问题,基于深度图的人脸识别方法性...

  • 深度图飞行像素去除

    本科毕设就是去除深度图中物体边缘的噪声,其中利用深度图生成点云后,视觉干扰最大的就是飞行像素了。关于飞行像素的空间...

  • iOS 基于charts 实现货币交易的深度图

    这几年虚拟货币交易的大热,对深度图和k线图的需求增多。今天就介绍一个基于charts来实现深度图控件,话不多说,先...

网友评论

      本文标题:深度图 DepthChartView

      本文链接:https://www.haomeiwen.com/subject/mfyujftx.html