How to get the location when using mouse wheel in chart?
Posted: Thu Apr 25, 2019 12:44 pm
Hi, When I use mouse wheel in chart to zoom in or zoom out, how could I get the location of my mouse movement? I creatchart such as, and add two event:sb_Scroll & ExampleThreadFedScrollBar_RangeChanged, can I get the location of mouse according to the property of e?
My purpose is: if I get the location of mouse, I can set the HorizontalScrollBar's value = the location mouse, my xAxis.ValueType = AxisValueType.DateTime, I can't set correctly HorizontalScrollBar's value as your code sample "Scroll bars" or "Histortic data review". I add 500 points in chart, my operations is:
when I zoom in or out, the HorizontalScrollBars locates uncorrectly. It appears far left or far right. Not as "Scroll bars" , the bar have a gap to far both side.
Code: Select all
HorizontalScrollBar sb = new HorizontalScrollBar(chart1);
sb.Minimum = 0;
sb.Maximum = (ulong)xLength1;
sb.Scroll += sb_Scroll;
sb.LargeChange = sb.Maximum;
sb.Offset = new PointIntXY(sb, 0, 40);
chart1.HorizontalScrollBars.Add(sb);
chart1.ViewXY.XAxes[0].RangeChanged += ExampleThreadFedScrollBar_RangeChanged;
private void sb_Scroll(Object sender, Arction.Wpf.Charting.ScrollEventArgs e)
{...}
private void ExampleThreadFedScrollBar_RangeChanged(Object sender, RangeChangedEventArgs e)
{...}
Code: Select all
double xmin = chart1.ViewXY.XAxes[0].DateTimeToAxisValue(fist_time);
double xmax = chart1.ViewXY.XAxes[0].DateTimeToAxisValue(last_time);
_xLength = xmax - xmin;
_scrollPosition = 0;
AxisX xAxis = chart1.ViewXY.XAxes[0];
xAxis.ValueType = AxisValueType.DateTime;
xAxis.ScrollMode = XAxisScrollMode.None;
xAxis.LabelsTimeFormat = "MM-dd HH:mm:ss";
chart1.ViewXY.XAxes[0].SetRange(xmin, xmax);
HorizontalScrollBar sb = new HorizontalScrollBar(chart1);
sb.Minimum = 0;
sb.Maximum = (ulong)(xmax-xmin);
sb.Scroll += sb_Scroll;
sb.LargeChange = sb.Maximum;
chart1.HorizontalScrollBars.Add(sb);
chart1.ViewXY.XAxes[0].RangeChanged += ExampleThreadFedScrollBar_RangeChanged;
private void ExampleThreadFedScrollBar_RangeChanged(Object sender, RangeChangedEventArgs e)
{
double d = e.NewMax - e.NewMin;
if (d < _xLength)
{
// Zooming in.
_xLength = d;
chart1.HorizontalScrollBars[0].Value = (ulong)(e.NewMin);
}
else if (d > _xLength)
{
// Zooming out.
_xLength = d;
chart1.HorizontalScrollBars[0].Value = _scrollPosition;
}
}
private void sb_Scroll(Object sender, Arction.Wpf.Charting.ScrollEventArgs e)
{
_scrollPosition = e.NewValue;
chart1.BeginUpdate();
chart1.ViewXY.XAxes[0].SetRange((double)e.NewValue + xmin, (double)e.NewValue + _xLength1 + xmin);
chart1.HorizontalScrollBars[0].Value = scrollPosition;
chart1.EndUpdate();
}