zoukankan      html  css  js  c++  java
  • C#画K线图代码

        /// <summary>
        /// 获取K线图的画图数据
        /// </summary>
        /// <returns></returns>
        public override CandlePriceData[] GetPriceCandleData()
        {
            int i;
            float fStep, py1, py2, fpy1, fpy2;      


    if (ChartDataCount <= 4)    // 当数据小于5时
            {
                priceCandleData = new CandlePriceData[ChartDataCount];
                float fNewXSpace = 30;
                for (i = 0; i < ChartDataCount; i++)
                {
                    fStep = ChartData[ChartIndex + i].Open - MinVal;
                    py1 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].Close - MinVal;
                    py2 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].Low - MinVal;
                    fpy1 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].High - MinVal;
                    fpy2 = (historySkin.FirstLine - fStep / PriceEveryHAverage);              


    if (py2 - py1 > 0)//跌
                    {
                        priceCandleData[i].RectanglePointF = new System.Drawing.PointF(historySkin.MarginLeft + i * fNewXSpace, py2);//计算矩形的左上角坐标
                        priceCandleData[i].IsUp = true;
                        priceCandleData[i].RectangleHeigh = py2 - py1;
                    }
                    else { priceCandleData[i].RectanglePointF = new System.Drawing.PointF(historySkin.MarginLeft + i * fNewXSpace, py1);
                        priceCandleData[i].IsUp = false;
                        priceCandleData[i].RectangleHeigh = py1 - py2; } priceCandleData[i].RectangleWidth = fNewXSpace-1;
                    priceCandleData[i].LineOneStart = new System.Drawing.PointF(historySkin.MarginLeft + 15 + i * fNewXSpace, fpy1);
                    priceCandleData[i].LineOneEnd = new System.Drawing.PointF(historySkin.MarginLeft + 15 + i * fNewXSpace, py1);
                    priceCandleData[i].LineTwoStart = new System.Drawing.PointF(historySkin.MarginLeft + 15 + i * fNewXSpace, py2);
                    priceCandleData[i].LineTwoEnd = new System.Drawing.PointF(historySkin.MarginLeft + 15 + i * fNewXSpace, fpy2);
                }
            }
            else
            {
                priceCandleData = new CandlePriceData[ChartDataCount];          


    for (i = 0; i < ChartDataCount; i++)
                {
                    fStep = ChartData[ChartIndex + i].Open - MinVal;
                    py1 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].Close - MinVal;
                    py2 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].Low - MinVal;
                    fpy1 = (historySkin.FirstLine - fStep / PriceEveryHAverage);
                    fStep = ChartData[ChartIndex + i].High - MinVal;
                    fpy2 = (historySkin.FirstLine - fStep / PriceEveryHAverage);              


    if (py2 - py1 > 0)//跌
                    {
                        if (py2 - py1 < 1)
                        {
                            py2 = py1 + 1;
                        }
                        priceCandleData[i].RectanglePointF = new System.Drawing.PointF(historySkin.MarginLeft+Fpx1+i*EveryHorizontalSpace, py1);
                        priceCandleData[i].IsUp = false;
                        priceCandleData[i].RectangleHeigh = py2 - py1;                    priceCandleData[i].LineOneEnd


    = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, py1);
                        priceCandleData[i].LineOneStart = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, fpy2); priceCandleData[i].LineTwoStart = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, py2);
                        priceCandleData[i].LineTwoEnd = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, fpy1);
                    }
                    else
                    {
                        if (py1 - py2 < 1)
                        {
                            py1 = py2 + 1;
                        }                    priceCandleData[i].RectanglePointF


    = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + i * EveryHorizontalSpace, py2);
                        priceCandleData[i].IsUp = true;
                        priceCandleData[i].RectangleHeigh = py1 - py2;                    priceCandleData[i].LineOneEnd


    = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, py2);
                        priceCandleData[i].LineOneStart = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, fpy2);
                        priceCandleData[i].LineTwoStart = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, py1);
                        priceCandleData[i].LineTwoEnd = new System.Drawing.PointF(historySkin.MarginLeft + Fpx1 + Fpx + i * EveryHorizontalSpace, fpy1);
                    }                priceCandleData[i].RectangleWidth


    = EveryHorizontalSpace-1;
                }
            }
            return priceCandleData;
        }

  • 相关阅读:
    解决electron-vue中无法使用Element的Tooltip组件
    解决Electron安装包下载慢的问题
    虚拟机VirtualBox 共享挂载问题:mount: /mnt/xxx: wrong fs type, bad option, bad superblock on xxx
    git 设置和取消代理
    (转载)数据库连接池到底应该设多大?这篇文章可能会颠覆你的认知
    MySQL主主复制+MMM实现高可用
    Mysql5.6主从热备配置
    java 启动 shell脚本
    redis批量删除key
    spring mvc异常统一处理(ControllerAdvice注解)
  • 原文地址:https://www.cnblogs.com/chuncn/p/1442962.html
Copyright © 2011-2022 走看看