Ejemplo n.º 1
0
        /// <summary>
        /// 绘制Y轴坐标刻度线
        /// </summary>
        /// <param name="axis">Y轴坐标</param>
        /// <param name="canvas">画布</param>
        /// <param name="y1">第一个Y</param>
        /// <param name="y2">第二个Y</param>
        public static void DrawYAxisLabelLine(AxisAbs axis, Canvas canvas, double y1, double y2)
        {
            if (!axis.DrawAxisLine || !DoubleHasValue(y1) || !DoubleHasValue(y2))
            {
                return;
            }

            var labelLinePath = new Path();

            labelLinePath.Style = axis.AxisLineStyle;
            if (labelLinePath.Style == null)
            {
                labelLinePath.Style = ChartStyleHelper.GetDefaultAxisLabelLineStyle();
            }

            Point point1, point2;

            if (axis.IsAxisYLeft())
            {
                point1 = new Point(canvas.Width, y1);
                point2 = new Point(canvas.Width, y2);
            }
            else
            {
                point1 = new Point(ChartConstant.ZERO_D, y1);
                point2 = new Point(ChartConstant.ZERO_D, y2);
            }

            PathFigure labelPathFigure = new PathFigure();

            labelPathFigure.StartPoint = point1;
            labelPathFigure.Segments.Add(new LineSegment(point2, true));
            labelLinePath.Data = new PathGeometry()
            {
                Figures = new PathFigureCollection(new PathFigure[] { labelPathFigure })
            };
            canvas.Children.Add(labelLinePath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 绘制Y轴坐标刻度线
        /// </summary>
        /// <param name="axis">Y轴坐标</param>
        /// <param name="canvas">画布</param>
        /// <param name="yList">Y轴刻度集合</param>
        public static void DrawYAxisLabelLine(AxisAbs axis, Canvas canvas, List <double> yList)
        {
            if (!axis.DrawAxisLine || yList == null || yList.Count == 0)
            {
                return;
            }

            var labelLinePath = new Path();

            labelLinePath.Style = axis.AxisLineStyle;
            if (labelLinePath.Style == null)
            {
                labelLinePath.Style = ChartStyleHelper.GetDefaultAxisLabelLineStyle();
            }

            GeometryGroup geometryGroup = new GeometryGroup();
            Point         point1, point2;
            double        y;
            int           lastIndex = yList.Count - 1;

            for (int i = 0; i < yList.Count; i++)
            {
                y = yList[i];
                if (axis.IsAxisYLeft())
                {
                    point1 = new Point(canvas.Width - axis.LabelSize, y);
                    point2 = new Point(canvas.Width, y);
                }
                else
                {
                    point1 = new Point(ChartConstant.ZERO_D, y);
                    point2 = new Point(axis.LabelSize, y);
                }

                PathFigure labelPathFigure = new PathFigure();
                labelPathFigure.StartPoint = point1;
                labelPathFigure.Segments.Add(new LineSegment(point2, true));
                geometryGroup.Children.Add(new PathGeometry()
                {
                    Figures = new PathFigureCollection(new PathFigure[] { labelPathFigure })
                });
            }

            //坐标轴
            if (axis.IsAxisYLeft())
            {
                point1 = new Point(canvas.Width, yList.First());
                point2 = new Point(canvas.Width, yList.Last());
            }
            else
            {
                point1 = new Point(ChartConstant.ZERO_D, yList.First());
                point2 = new Point(ChartConstant.ZERO_D, yList.Last());
            }
            PathFigure axisPathFigure = new PathFigure();

            axisPathFigure.StartPoint = point1;
            axisPathFigure.Segments.Add(new LineSegment(point2, true));
            geometryGroup.Children.Add(new PathGeometry()
            {
                Figures = new PathFigureCollection(new PathFigure[] { axisPathFigure })
            });


            labelLinePath.Data = geometryGroup;
            canvas.Children.Add(labelLinePath);
        }