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

posted on 2009-04-24 15:28  chuncn  阅读(8330)  评论(3编辑  收藏  举报

导航