/// <summary> /// 使用配置的颜色属性重新绘制折线图。 /// </summary> public void DrawChart() { ClearChart(); if (XAxis == null || YAxis == null || XAxis.Count() == 0 || YAxis.Count() == 0) { return; } //绘制坐标 var xCellWidth = (Width - _yAxisWidth) / XAxis.Count(); var yCellHeight = (Height - _xAxisHeight) / YAxis.Count(); DrawAxis(xCellWidth, yCellHeight); //绘制网格线 var canvasWidth = Width - _yAxisWidth; var canvasHeight = Height - _xAxisHeight; DrawGrid(xCellWidth, yCellHeight, canvasWidth, canvasHeight); //绘制点和线 if (Values == null) { return; } DrawPointAndLineAndArea(xCellWidth, yCellHeight); }
/// <summary> /// 绘制网格。 /// </summary> internal void DrawGrid(double xCellWidth, double yCellHeight, double canvasWidth, double canvasHeight) { var path = ""; for (int i = 0; i < XAxis.Count(); i++) { path += $"M {xCellWidth * i},0 V {canvasHeight}"; } for (int i = 0; i < YAxis.Count(); i++) { path += $"M 0,{canvasHeight - yCellHeight * i} H {canvasWidth}"; } gridPath.Data = Geometry.Parse(path); }