winforms - Time Series in MS Charts with C# -


this question has answer here:

i using ms charts plot points time series, this

chart1.series[0].points.addxy(time, voltage);   

i large number of data (1 point / 100 ms), @ end of day program slow plot new data. therefore, want able scroll x-axis of chart automatically after amount of time, example 30 mins or so... want keep data plotted not directly visible user, hidden left of chart..

how can it?

edit : see edit @ end along solution zooming in set

you should plot visible, nothing else.

either keep old values in memory or persist them disk , load them needed.

here example:

i have 1 000 000 points in memory , can seamlessly scroll , drawing happens instantly.

using system; using system.collections.generic; using system.linq; using system.windows.forms; using system.windows.forms.datavisualization.charting;  namespace windowsformsapplication1 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          public list<int> values { get; private set; }          public int valuestoshow         {             { return 20; }         }          private void form1_load(object sender, eventargs e)         {             values = new list<int>();             var random = new random();             (int = 0; < 1000000; i++)             {                 int next = random.next(10, 50);                 values.add(next);             }              hscrollbar1.maximum = (values.count - 1) - valuestoshow;         }          private void hscrollbar1_scroll(object sender, scrolleventargs e)         {             var hscrollbar = (hscrollbar) sender;             int value = hscrollbar.value;             ienumerable<int> enumerable = values.skip(value).take(valuestoshow);              chart1.series.clear();             var series = new series();              foreach (int in enumerable)             {                 series.points.add((double) i);             }              chart1.series.add(series);         }     } } 

result :

enter image description here

notes:

1 day of values = 86m points, multiply 4 (the size of float) , 350mb of data.

i guess can keep amount of data in memory according today's pcs specs, if not save periodically.

it should quite easy read values file @ specific position using binaryreader, left exercise; queue might temporarily storing them before persisting them hdd.


edit

i have somehow tried use official approach zoom features i've encountered few issues :

  • even 1m point slow
  • reducing number of points fixes have no access previous , future points
  • trying hack axisviewchanging event inconclusive, adding/removing more points when @ position in scroll bar -> scroll bar change it's position, i.e. not user friendly. (i've stopped in middle of process it's hacky/unreliable imo)
  • adding "load previous/next sets" buttons better hack more user unfriendly, click them tons of time.

my final conclusion :

to zoom, add 2 buttons change value of valuestoshow.

enter image description here

obviously lose ability select points using rectangle can go part of data set instantly.

using system; using system.collections.generic; using system.linq; using system.windows.forms; using system.windows.forms.datavisualization.charting;  namespace windowsformsapplication1 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          public list<int> values { get; private set; }          public int valuestoshow { get; set; }          private void form1_load(object sender, eventargs e)         {             valuestoshow = 20;              values = new list<int>();             var random = new random();             (int = 0; < 1000000; i++)             {                 int next = random.next(10, 50);                 values.add(next);             }              hscrollbar1.maximum = (values.count - 1) - valuestoshow;              refreshchart();         }          private void hscrollbar1_scroll(object sender, scrolleventargs e)         {             refreshchart();         }          private ienumerable<int> getcurrentvalues(int value)         {             return values.skip(value).take(valuestoshow);         }          private int getcurrentposition()         {             return hscrollbar1.value;         }          private void button1_click(object sender, eventargs e)         {             valuestoshow /= 2;             refreshchart();         }          private void button2_click(object sender, eventargs e)         {             valuestoshow *= 2;             refreshchart();         }          private void refreshchart()         {             int value = getcurrentposition();             ienumerable<int> enumerable = getcurrentvalues(value);              chart1.series.clear();             var series = new series();              foreach (int in enumerable)             {                 series.points.add((double) i);             }              chart1.series.add(series);         }     } } 

final notes :

1m points seems reasonable (20 minutes of data), more , starts slow down, tried 84m unpractical.

to make more user friendly can zoom while user uses mouse wheel.

if can afford other solutions, can performance out-of-the-box wpf and/or commercial solutions devexpress have pay ... here offer 0$ solution lacks selection rectangle fast time :d


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -