c# - OxyPlot Add points after axis drag -
i want add points dynamicall after axis drag, how can figgure out, axis dragged , where? can start point , end point of displayed axes(x
)?
using oxyplot; using system; using system.collections.generic; using system.linq; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace wpfapplication15 { /// <summary> /// interaction logic mainwindow.xaml /// </summary> /// public class dataloading { public plotmodel plotmodel { get; set; } oxyplot.axes.linearaxis x; oxyplot.axes.linearaxis y; private oxyplot.series.lineseries firstseries; private oxyplot.series.lineseries secondseries; public dataloading() { plotmodel = new plotmodel(); x = new oxyplot.axes.linearaxis() { position = oxyplot.axes.axisposition.bottom, minimum=-2, maximum=2 }; y = new oxyplot.axes.linearaxis() { position = oxyplot.axes.axisposition.left, ispanenabled = false }; firstseries = new oxyplot.series.lineseries(); secondseries = new oxyplot.series.lineseries(); firstload(); secondload(); plotmodel.axes.add(x); plotmodel.axes.add(y); } private void firstload() { firstseries.points.add(new datapoint(1, 1)); firstseries.points.add(new datapoint(2, 2)); firstseries.points.add(new datapoint(3, 3)); firstseries.points.add(new datapoint(4, 3)); firstseries.points.add(new datapoint(5, 3)); plotmodel.series.add(firstseries); } private void secondload() { firstseries.points.add(new datapoint(6, 1)); firstseries.points.add(new datapoint(7, 2)); firstseries.points.add(new datapoint(8, 3)); firstseries.points.add(new datapoint(9, 3)); firstseries.points.add(new datapoint(10, 3)); } } public partial class mainwindow : window { public mainwindow() { initializecomponent(); datacontext= new dataloading(); } } }
using galasoft.mvvmlight.command; using oxyplot; using system; using system.collections.generic; using system.diagnostics; using system.linq; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace wpfapplication15 { /// <summary> /// interaction logic mainwindow.xaml /// </summary> /// public class dataloading { public plotmodel plotmodel { get; set; } public icommand testcommand { get; set; } oxyplot.axes.linearaxis x; oxyplot.axes.linearaxis y; private oxyplot.series.lineseries firstseries; private oxyplot.series.lineseries secondseries; private int =0; public dataloading() { testcommand = new relaycommand(()=>showactualpoints()); plotmodel = new plotmodel(); x = new oxyplot.axes.linearaxis() { position = oxyplot.axes.axisposition.bottom, minimum=1, maximum=5 }; y = new oxyplot.axes.linearaxis() { position = oxyplot.axes.axisposition.left, ispanenabled = false }; firstseries = new oxyplot.series.lineseries(); secondseries = new oxyplot.series.lineseries(); firstload(); plotmodel.axes.add(x); plotmodel.axes.add(y); oxyplot.wpf.plotview pv = new oxyplot.wpf.plotview(); plotmodel.axes[0].axischanged += (o, e) => { double lastpoint = (from y in firstseries.points select y.x).min(); showactuals(lastpoint); }; } public delegate void beginupdate(); public void showactuals(double inputlastpoint) { if (inputlastpoint > plotmodel.axes[0].actualminimum) { debug.writeline("need load points"); beginupdate bu = new beginupdate(secondload); iasyncresult result = bu.begininvoke(null,null); } else { debug.writeline("no need load points"); } } private void firstload() { firstseries.points.add(new datapoint(1, 1)); firstseries.points.add(new datapoint(2, 2)); firstseries.points.add(new datapoint(3, 3)); firstseries.points.add(new datapoint(4, 3)); firstseries.points.add(new datapoint(5, 3)); plotmodel.series.add(firstseries); } private void secondload() { random rnd = new random(); firstseries.points.insert(0,new datapoint(--i, rnd.nextdouble())); system.threading.thread.sleep(1000); plotmodel.invalidateplot(true); } private void showactualpoints() { debug.writeline("y:{0}",plotmodel.axes[1].actualmaximum); debug.writeline("x:{0}", plotmodel.axes[0].actualmaximum); debug.writeline(plotmodel.series[0].getnearestpoint(new screenpoint(plotmodel.axes[0].actualmaximum, plotmodel.axes[1].actualmaximum), false)); } } public partial class mainwindow : window { public mainwindow() { initializecomponent(); datacontext= new dataloading(); } } }
Comments
Post a Comment