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