Esempio n. 1
0
        /// <summary>
        /// 绘制下方时间轴
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        void DrawTimeLine(DrawingContext dc, double left, double top, double width, double height)
        {
            //每条记录的宽度
            var itemOffset = this.ChartWidth / TotalItemCount;

            //draw time line
            var yearLast = 0;

            for (var i = 0; i < TotalItemCount; i++)
            {
                var xoffset = (int)(i * itemOffset) + left + 0.5;
                var year    = priceInfo.PriceList[i].Date.Year;//(int)(priceInfo.PriceList[i].Date / 10000);
                if (year > yearLast)
                {
                    //格式文本,指定位置
                    FormattedText txt = new FormattedText(year.ToString(),
                                                          System.Globalization.CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight, new Typeface("Verdana"),
                                                          12, new SolidColorBrush(Color.FromRgb(64, 64, 64)));
                    //绘制文本
                    dc.DrawText(txt, new Point(xoffset, top + height - 16));
                }
                yearLast = year;
            }

            //draw curve line
            var highest = priceInfo.getHighestPrice(0, TotalItemCount).High;
            var lowest  = priceInfo.getLowestPrice(0, TotalItemCount).Low;

            var pixelcount = 3;
            var inc        = (int)(TotalItemCount * pixelcount / this.ChartWidth);

            if (inc == 0)
            {
                inc = 1;
            }

            //var color = "#30b8f3";
            var pen = getPen(48, 184, 243, 1);
            //draw line curve.
            PathFigure   pf = new PathFigure();
            PathGeometry pg = new PathGeometry();

            pg.Figures.Add(pf);

            for (var i = 0; i < TotalItemCount; i += inc)
            {
                var xoffset = (int)(i * itemOffset) + 0.5 + left;
                var yClose  = (int)((highest - priceInfo.PriceList[i].Close) / (highest - lowest) * (height - 12)) + 0.5 + top;

                if (i == 0)
                {
                    pf.StartPoint = new Point(xoffset, yClose);
                }
                else
                {
                    pf.Segments.Add(new LineSegment(new Point(xoffset, yClose), true));
                }
            }

            dc.DrawGeometry(Brushes.Transparent, pen, pg);

            //draw item time region button
            double x      = (int)(drawItemStartIndex * itemOffset) + left + 0.5;
            var    xwidth = (int)(drawItemCount * itemOffset);

            var brush = getBrush(224, 224, 255, 128);

            pen = getPen(224, 224, 255, 1, 128);
            dc.DrawRectangle(brush, pen, new Rect(x, top, xwidth, height));
        }