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;
        }

  • 相关阅读:
    [转] 英语飙升的好方法
    jndi数据源方式配制SPY
    OJB查询
    ODP.NET应用之我所见
    C#中利用ODP实现瞬间导入百万级数据详解
    Sys.Extended.UI' is null or not an object 中文的訊息
    oracle数据库连接字符串
    seo
    宽幅FLASH产品展示代码多图带左右显示按钮 图
    网站盈利模式分类详解
  • 原文地址:https://www.cnblogs.com/chuncn/p/1442962.html
Copyright © 2011-2022 走看看