c# - WPF coordinate System update -
i created coordinate system on canvas element. draw every got value red point , connect old one.
see here:
i'm getting every second 10 values.
1 value = 1 pixel
the red line represent values, i'm getting constant value testing.
my goal update drawing when reaches end of coordinate system. want push drawing left , draw next points.
my goal is:
- i dont want lose points in graph because later want zoom in , out
- i dont want slow down system less possible ...
this code not sure how can update graph in ending part....
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 connection point pone = new point(xold, yold); point ptwo = new point(t, value); //connect old point 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 static linegroup new point linegroupdrw1.children.add(connectorgeometry); if (coordinatesystem.width > t) { // draw graph coordinatesystem.children.add(path); } else { //to : 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; }
just put ui inside scrollviewer. forget trying "move" lines around.
<window x:class="miscsamples.signalgraph" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="signalgraph" height="300" width="300"> <scrollviewer verticalscrollbarvisibility="auto" horizontalscrollbarvisibility="auto"> <grid x:name="coordinatesystem"> </grid> </scrollviewer> </window>
code behind (taken code , improved little bit)
public partial class signalgraph : window { private system.threading.timer timer; private random random = new random(); public signalgraph() { initializecomponent(); timer = new system.threading.timer(x => drawrandomline(), null, 0, 100); } private void drawrandomline() { dispatcher.begininvoke((action) (() => drawpoly(random.next(0,100))), null); } static double xold = 32; static double yold = 580; static double t = 32; path path; static geometrygroup linegroupdrw1 = new geometrygroup(); public void drawpoly(double value) { //increase point position t = t+5; //generate 2 point connection var pone = new point(xold, yold); var ptwo = new point(t, value); //connect old point new var linegroup = new geometrygroup(); var connectorgeometry = new linegeometry {startpoint = pone, endpoint = ptwo}; linegroup.children.add(connectorgeometry); path = new path { data = linegroup, strokethickness = 1, stroke = brushes.red, fill = brushes.red }; //fill static linegroup new point linegroupdrw1.children.add(connectorgeometry); //if (coordinatesystem.actualwidth > t) //{ // draw graph coordinatesystem.children.add(path); //} //else //{ // //to : update drawing // updatedrawingend(); //} //refresh values xold = t; yold = value; } }
result:
Comments
Post a Comment