コード例 #1
0
        /// <summary>
        /// 绘制X轴坐标刻度线
        /// </summary>
        /// <param name="axis">X轴坐标</param>
        /// <param name="canvas">画布</param>
        /// <param name="x1">第一个X</param>
        /// <param name="x2">第二个X</param>
        public static void DrawXAxisLabelLine(AxisAbs axis, Canvas canvas, double x1, double x2)
        {
            if (!axis.DrawAxisLine || !DoubleHasValue(x1) || !DoubleHasValue(x2))
            {
                return;
            }

            var labelLinePath = new Path();

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

            Point point1, point2;

            if (axis.IsAxisXBottom())
            {
                point1 = new Point(ChartConstant.ZERO_D, ChartConstant.ZERO_D);
                point2 = new Point(canvas.Width, ChartConstant.ZERO_D);
            }
            else
            {
                point1 = new Point(ChartConstant.ZERO_D, canvas.Height);
                point2 = new Point(canvas.Width, canvas.Height);
            }

            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);
        }
コード例 #2
0
        /// <summary>
        /// 绘制X轴坐标刻度线
        /// </summary>
        /// <param name="axis">X轴坐标</param>
        /// <param name="canvas">画布</param>
        /// <param name="xList">X轴刻度集合</param>
        public static void DrawXAxisLabelLine(AxisAbs axis, Canvas canvas, List <double> xList)
        {
            if (!axis.DrawAxisLine || xList == null || xList.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        x;
            int           lastIndex = xList.Count - 1;

            for (int i = 0; i < xList.Count; i++)
            {
                x = xList[i];
                if (axis.IsAxisXBottom())
                {
                    point1 = new Point(x, ChartConstant.ZERO_D);
                    point2 = new Point(x, axis.LabelSize);
                }
                else
                {
                    point1 = new Point(x, canvas.Height - axis.LabelSize);
                    point2 = new Point(x, canvas.Height);
                }

                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.IsAxisXBottom())
            {
                point1 = new Point(xList.First(), ChartConstant.ZERO_D);
                point2 = new Point(xList.Last(), ChartConstant.ZERO_D);
            }
            else
            {
                point1 = new Point(xList.First(), canvas.Height);
                point2 = new Point(xList.Last(), canvas.Height);
            }
            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);
        }