/// <summary> /// 清除数据 /// </summary> protected virtual void Clear() { if (_rootCanvas == null || FastSourceInstance.GetCachedCandleList().Count == 0 || CommonData.ViewPortWidth == 0 || CommonData.ViewPortHeight == 0) { return; } _rootCanvas.ClearVisual(); }
/// <summary> /// 画y轴 /// </summary> private void ProduceYaxis() { if (_rootCanvas == null || CommonData.ViewPortWidth == 0 || CommonData.ViewPortHeight == 0) { return; } _rootCanvas.ClearVisual(); //y轴刻度位置集合 List <Point> YaxisPoints = new List <Point>(); //y轴刻度值集合 List <double> YValues = new List <double>(); double ymax = CommonData.YMaxValue; double ymin = CommonData.YMinValue; if (ymax == 0 && ymin == 0) { return; } CommonData.Scale = CommonData.ViewPortHeight / (ymax - ymin); //y轴刻度之间的间隔,这里始终显示5个刻度 double span = Math.Round((ymax - ymin) / 5, NumberPointCount); double yaxis = ymin; //y轴路径 StreamGeometry axispathStream = new StreamGeometry(); StreamGeometryContext axisContext = axispathStream.Open(); while (Math.Round(ymax - yaxis, 2) >= 0) { //循环画路径 YValues.Add(Math.Round(yaxis, 2)); double yvalue = CommonData.ViewPortHeight - (yaxis - ymin) * CommonData.Scale + CommonData.HeightOffet / 2; Point p = new Point(CommonData.ViewPortWidth, yvalue); YaxisPoints.Add(p); axisContext.BeginFigure(new Point(0, p.Y), false, false); axisContext.LineTo(p, true, false); yaxis += span; if (span == 0) { break; } } axisContext.Close(); //在画布画路径 _rootCanvas.DrawingYaxis(axispathStream, 1, YaxisPoints, YValues); }