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

  • 相关阅读:
    [轉]Flex实现代码分离mxml/as
    [轉]PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now 问题的解决
    [轉]mysqli & pdo使用实例和详解
    JSON格式驗證以及格式說明
    [轉]can't return a result set in the given context及参数解释
    PHP ADODB資源
    [轉]Virtual PC 网络设置(Networking)
    [轉]20个非常有用的PHP类库
    [轉]MySQL存储过程 ERROR Handler 异常处理
    [轉]如何通过Jquery获取radio的值
  • 原文地址:https://www.cnblogs.com/chuncn/p/1442962.html
Copyright © 2020-2023  润新知