我在画布元素上创建了一个坐标系。我为每一个得到的价值画一个红点,并将它与旧的连接起来。
看这里:
我每秒得到大约 10 个值。
1 个值 = 1 个像素
红线代表值,我得到一个常数值只是为了测试。
我的目标是在绘图到达我的坐标系末尾时更新它。我想把我的画推到左边并画下一个点。
我的目标是:
- 我不想丢失图表中的点,因为稍后我想放大和缩小
- 我不想让我的系统尽可能慢...
这是我的代码,但不确定如何更新结尾部分的图表......
static double xOld = 32;
static double yOld = 580;
static double t = 32;
System.Windows.Shapes.Path path;
static GeometryGroup lineGroupDrw1 = new GeometryGroup();
....
public void drawPoly(double value)
{
//increase point position
t++;
//generate 2 point for the connection
Point pOne = new Point(xOld, yOld);
Point pTwo = new Point(t, value);
//connect old point with new
GeometryGroup lineGroup = new GeometryGroup();
LineGeometry connectorGeometry = new LineGeometry();
connectorGeometry.StartPoint = pOne;
connectorGeometry.EndPoint = pTwo;
lineGroup.Children.Add(connectorGeometry);
path = new System.Windows.Shapes.Path();
path.Data = lineGroup;
path.StrokeThickness = 1;
path.Stroke = path.Fill = Brushes.Red;
//fill the static linegroup with a new point
lineGroupDrw1.Children.Add(connectorGeometry);
if (coordinateSystem.Width > t)
{
// draw graph
coordinateSystem.Children.Add(path);
}
else
{
//To do : update drawing
updateDrawingEnd();
}
//refresh values
xOld = t;
yOld = value;
}
....
public void updateDrawingEnd()
{
path = new System.Windows.Shapes.Path();
path.Data = lineGroupDrw1;
path.StrokeThickness = 1;
path.Stroke = path.Fill = Brushes.Yellow;
coordinateSystem.Children.Add(path);
t = 145;
}