c# - Smooth scroling in chart with datetime x axis -
i have simple graph plotted in chart. on x-axis values datetime
values.
public partial class form1 : form { list<double> valuelist = new list<double>(); list<datetime> timelist = new list<datetime>(); public form1() { initializecomponent(); // fill lists values (int = 0; < 2000; i++) { double value = math.sin(i/20.0); valuelist.add(value); timelist.add(datetime.now.addminutes(i + 2)); } // add values chart (int = 0; < valuelist.count; i++) { this.chart1.series[0].points.addxy(timelist[i], valuelist[i]); } this.chart1.chartareas[0].axisx.labelstyle.format = "dd.mm-hh:mm"; } private void form1_load(object sender, eventargs e) { chart1.series[0].xvaluetype = chartvaluetype.datetime; chart1.chartareas[0].axisx.maximum = timelist.max().tooadate(); chart1.chartareas[0].axisx.minimum = timelist.min().tooadate(); chart1.chartareas[0].cursorx.autoscroll = true; chart1.chartareas[0].cursory.autoscroll = true; chart1.chartareas[0].cursorx.isuserselectionenabled = true; chart1.chartareas[0].cursory.isuserselectionenabled = true; chart1.chartareas[0].axisx.scaleview.zoomable = true; chart1.chartareas[0].axisy.scaleview.zoomable = true; datetime intervall = timelist.min().addhours(3); chart1.chartareas[0].axisx.scaleview.zoom(chart1.chartareas[0].axisx.minimum, intervall.tooadate()); // disable zoom-reset button chart1.chartareas[0].axisx.scrollbar.buttonstyle = scrollbarbuttonstyles.smallscroll; // set scrollbar small change blocksize chart1.chartareas[0].axisx.scaleview.smallscrollsize = intervall.tooadate(); } }
my problem cannot scrollbar move smoothly. when plot y-values , use double
values axisx.maximum
, axisx.minimum
, axisx.scaleview.zoom
, axisx.scaleview.smallscrollsize
works charm. use datetime
x-values can scroll in steps. know how surpass this? have feeling piece of code obstacle:
// set scrollbar small change blocksize (e.g. 100) chart1.chartareas[0].axisx.scaleview.smallscrollsize = intervall.tooadate();
edit:
the interval x-axis automatic, range set zoomlevel of chart1.chartareas[0].axisx.scaleview.zoom
. here picture:
edit 2:
the values x-axis datetime-values simulating sampling of 1 value every minute:
timelist.add(datetime.now.addminutes(i + 2));
because lot of values did not set interval. code posted way, can copied , run right away try out.
you scrolling interval wrong.
it should not start of data step want go when scrolling.
looks want scroll 3 hours?
here do:
chart1.chartareas[0].axisx.scaleview.smallscrollsizetype = datetimeintervaltype.hours; chart1.chartareas[0].axisx.scaleview.smallscrollsize = 3;
if wanted use datetime.tooadate
double achieve same need start @ first day of datatime
data type (0
aka 'dawn of time' aka 1899-12-30
) , add 3 hours:
datetime interval = datetime.fromoadate(0).addhours(3); chart1.chartareas[0].axisx.scaleview.smallscrollsizetype = datetimeintervaltype.number; chart1.chartareas[0].axisx.scaleview.smallscrollsize = interval.tooadate();
to allow dragging lift smoothly may work better setting smallscrollsize
:
chart1.chartareas[0].axisx.scaleview.smallscrollminsizetype =datetimeintervaltype.minutes; chart1.chartareas[0].axisx.scaleview.smallscrollminsize = 60;
use unit , numbers! work if don't set smallscrollminsize
.
Comments
Post a Comment