How do I plot real-time signal in WPF and C# .net 3.5? -
i trying plot real-time signal, signal vs time, wpf , c# (dynamic info display); 1 time signal generated, should showed on plot chart instantly; signal can generated fast (on order of mili-second (0.001 second)); best way it? suggestion appreciated.thanks.
edit: illustration code highly appreciated.
here have tried:
plot initiation:
#region constructor public signalstatsdisplay() { initializecomponent(); plotter.legend.remove(); _initialchildrencount = plotter.children.count; int count = plotter.children.count; //do not remove initial children if (count > _initialchildrencount) { (int = count - 1; >= _initialchildrencount; i--) { plotter.children.removeat(i); } } _ncolorchannels = 4; _lineprofilecolor = new color[4]; _lineprofilecolor[0] = colors.transparent; _lineprofilecolor[1] = colors.red; _lineprofilecolor[2] = colors.black; _lineprofilecolor[3] = colors.blue; //linegraph lg = new linegraph(); lineandmarker<markerpointsgraph> lg = new lineandmarker<markerpointsgraph>(); circlepointmarker pm = new circlepointmarker { size = 10, fill = brushes.green }; // markerpointsgraph mpg = new markerpointsgraph(); if (_ncolorchannels > 0) // plotter init { _datax = new list<int[]>(); _datay = new list<int[]>(); int[] dataxonech = new int[1]; int[] datayonech = new int[1]; dataxonech[0] = 0; datayonech[0] = 0; /*circlepointmarker marker = new circlepointmarker(); marker.fill = new solidcolorbrush(_lineprofilecolor[0]); marker.pen = new pen(marker.fill, 0); marker.size = 2; int linewidth = 1;*/ (int = 0; < 4; i++) { _datax.add(dataxonech); // info x-y mapping init _datay.add(datayonech); enumerabledatasource<int> xonech = new enumerabledatasource<int>(dataxonech); enumerabledatasource<int> yonech = new enumerabledatasource<int>(datayonech); xonech.setxmapping(xval => xval); yonech.setxmapping(yval => yval); compositedatasource dsonech = new compositedatasource(xonech, yonech); // lineprofilecolorsetup(); lg = plotter.addlinegraph(dsonech, (new pen(brushes.green, 2)), pm, (new pendescription("data"))); // lg = plotter.addlinegraph(dsonech, // colors.transparent, // 2, // "data"); // pm.filteringenabled = false; } plotter.fittoview(); } else { return; } }
data update:
(int = 0; < 1; i++) { if (_datax[i].length == _datay[i].length) { enumerabledatasource<int> xonech = new enumerabledatasource<int>(_datax[i]); xonech.setxmapping(xval => xval); enumerabledatasource<int> yonech = new enumerabledatasource<int>(_datay[i]); yonech.setymapping(yval => yval); compositedatasource ds = new compositedatasource(xonech, yonech); action updatedata = delegate() { // ((linegraph)plotter.children.elementat(startindex + i)).datasource = ds; // ((linegraph)plotter.children.elementat(startindex + i)).linepen = new pen(new solidcolorbrush(colors.green), 1); // ((pointsgraphbase)plotter.children.elementat(startindex + i)).datasource = ds; ((pointsgraphbase)plotter.children.elementat(startindex + + 1)).datasource = ds; // } // (plotter.children.elementat(startindex + i)).datasource = ds; }; this.dispatcher.invoke(system.windows.threading.dispatcherpriority.normal, updatedata); } }
the problem have when signal comes in fats, new signal generated every mili-second, seems graph generate new marker every 1 second, don't understand.
the basic thought generate plotter.addlinegraph, update datasource. seems not working. thought maybe on wrong direction.
i not c# or wpf expert. when lineandmarker not work expected, started doubting. wondering general way people display real-time signal (rapidly changing, time span between samples on mili-second) using wpf , c#.
i found did wrong. here part problem happens:
_pxlvalallchan[0, signalindex] = pxlvalue; datetime currenttime = datetime.now; //has come real file: tiff timespan timespan = currenttime - _starttime; _timestampallchan[0, signalindex] = convert.toint16(timespan.totalseconds); _pxlvalonechan = new int[_signallength]; // no need new every time _timestamponechan = new int[_signallength]; (int = 0; <= signalindex; i++) { _pxlvalonechan[i] = _pxlvalallchan[0, i]; //_timestamponechan[i] = _timestampallchan[0, i]; _timestamponechan[i] = i; } _signaldisplay.setdata(_timestamponechan, _pxlvalonechan, 0, true);
my x info based on time. consider initiation of programme starting point, maintain track of time elapse subtracting starting time current time. time elapse saved x-axis info (see line commented out). , causes problem. when simple alter x-axis info index, problem gone. graph update pretty fast. although have not figure out how should alter logic still utilize time elapse x-axis data, culprit of slow updating on graph.
c# wpf plot dynamic-data-display real-time-data
No comments:
Post a Comment