private void PrimitiveGetMinAndMaxValue(AxisAbs axis, ValueCollection values, out double min, out double max) { min = double.NaN; max = double.NaN; if (values == null || values.Count == 0) { return; } double pre = double.IsNaN(axis.PRE) ? ChartConstant.ZERO_D : axis.PRE; IChartAxisValue chartAxisValue; IChartAxisDoubleValue doubleValue; foreach (var value in values) { chartAxisValue = value as IChartAxisValue; if (chartAxisValue == null) { doubleValue = value as IChartAxisDoubleValue; if (doubleValue != null) { this.GetIChartAxisDoubleValueMinAndMax(axis, doubleValue, ref pre, ref min, ref max); } } else { this.GetIChartAxisValueMinAndMax(axis, chartAxisValue, ref pre, ref min, ref max); } } }
private void GetIChartAxisValueMinAndMax(AxisAbs axis, IChartAxisValue chartAxisValue, ref double pre, ref double min, ref double max) { object obj; switch (axis.AxisType) { case AxisType.X: obj = chartAxisValue.GetXValue(); break; case AxisType.Y: obj = chartAxisValue.GetYValue(); break; default: throw new NotImplementedException(axis.AxisType.ToString()); } if (obj == null) { return; } if (obj is IEnumerable) { this.GetCollectionMinAndMax(obj, ref pre, ref min, ref max); } else { this.GetMinAndMax(obj, ref pre, ref min, ref max); } }
/// <summary> /// 创建坐标轴Label控件 /// </summary> /// <param name="axis">坐标轴</param> /// <param name="labelText">标签文本</param> /// <returns>Label控件</returns> public static TextBlock CreateLabelControl(AxisAbs axis, string labelText) { var textBlock = new TextBlock(); textBlock.Text = labelText; if (axis.LabelStyle == null) { textBlock.Style = ChartStyleHelper.GetAxisLabelStyle(axis.DockOrientation); } else { textBlock.Style = axis.LabelStyle; } return(textBlock); }
private void GetIChartAxisDoubleValueMinAndMax(AxisAbs axis, IChartAxisDoubleValue doubleValue, ref double pre, ref double min, ref double max) { switch (axis.AxisType) { case AxisType.X: this.PrimitiveGetIChartAxisDoubleValueMinAndMax(doubleValue.GetXValue1(), ref pre, ref min, ref max); this.PrimitiveGetIChartAxisDoubleValueMinAndMax(doubleValue.GetXValue2(), ref pre, ref min, ref max); break; case AxisType.Y: this.PrimitiveGetIChartAxisDoubleValueMinAndMax(doubleValue.GetYValue1(), ref pre, ref min, ref max); this.PrimitiveGetIChartAxisDoubleValueMinAndMax(doubleValue.GetYValue2(), ref pre, ref min, ref max); break; default: throw new NotImplementedException(axis.AxisType.ToString()); } }
/// <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> /// 测量标签文本大小 /// </summary> /// <param name="axis">坐标轴</param> /// <param name="labelText">标签文本</param> /// <returns>标签文本大小</returns> public static Size MeasureLabelTextSize(AxisAbs axis, string labelText) { if (_measureTextLabel == null) { _measureTextLabel = new TextBlock(); } TextBlock measureTextLabel = _measureTextLabel; measureTextLabel.Text = labelText; if (axis.LabelStyle == null) { measureTextLabel.Style = ChartStyleHelper.GetAxisLabelStyle(axis.DockOrientation); } else { measureTextLabel.Style = axis.LabelStyle; } var size = UITextHelper.MeasureTextSize(measureTextLabel); measureTextLabel.Style = null; return(size); }
/// <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); }