How to add a HorizontalScrollBar if xAxis is datatime?
Posted: Thu Feb 28, 2019 2:24 am
Hi,
I want to add a horizontalscrollbar as the Historic data review in demo, and the valuetype of xAxis is AxisValueType.DateTime as the teperature graph in demo. Now, I have two problems:
1. if I write code as follows:
AxisX xAxis = _chart.ViewXY.XAxes[0];
xAxis.ValueType = AxisValueType.DateTime;
chartView.XAxes[0].RangeChanged += ExampleThreadFedScrollBar_RangeChanged;
xAxis.ScrollMode = XAxisScrollMode.Scrolling;
xAxis.Title.Text = "Time";
xAxis.AutoFormatLabels = false;
xAxis.LabelsTimeFormat = "dd/MM\nHH:mm.ss";
//Convert DateTime values to axis values
DateTime now = DateTime.Now;
double minX = xAxis.DateTimeToAxisValue(now);
double maxX = xAxis.DateTimeToAxisValue(now) + 30;
xAxis.SetRange(minX, maxX);
chartView.XAxes[0].LabelsAngle = 90;
then, I didn`t work, and tell me:
chart.HorizontalScrollBars[0].Value = _scrollPosition;(System.ArgumentOutOfRangeException)
2. I add point according to timer(1 point per 200ms), if the xAxis is datetime, how could I get the _previousX? I add the following code:
if (_isRealtime == true)
{
// This triggers X axis' RangeChanged event.
chartView.XAxes[0].ScrollPosition = _previousX;
// In "real-time" mode update scroll bar's LargeChange,
// Maximum and Value properties.
HorizontalScrollBar sb = _chart.HorizontalScrollBars[0];
sb.LargeChange = (ulong)((double)_generatedPoints / ((double)_generatedPoints / (_samplingFrequency * _xLength / 10)) + 0.5);
sb.Maximum = (ulong)_generatedPoints - 1;
sb.Value = (ulong)_generatedPoints - sb.LargeChange;
}
else
{
// In "non-real-time" mode update only LargeChange and
// Maximum. Do not update Value so that scroll bar's thumb
// stays in one place.
HorizontalScrollBar sb = _chart.HorizontalScrollBars[0];
sb.LargeChange = (ulong)((double)_generatedPoints / ((double)_generatedPoints / (_samplingFrequency * _xLength / 10)) + 0.5);
sb.Maximum = (ulong)_generatedPoints - 1;
}
but the scrollbar can't work, could you solve them above two problems?
If you can, can you give me a example in order to study?
Thank you !
I want to add a horizontalscrollbar as the Historic data review in demo, and the valuetype of xAxis is AxisValueType.DateTime as the teperature graph in demo. Now, I have two problems:
1. if I write code as follows:
AxisX xAxis = _chart.ViewXY.XAxes[0];
xAxis.ValueType = AxisValueType.DateTime;
chartView.XAxes[0].RangeChanged += ExampleThreadFedScrollBar_RangeChanged;
xAxis.ScrollMode = XAxisScrollMode.Scrolling;
xAxis.Title.Text = "Time";
xAxis.AutoFormatLabels = false;
xAxis.LabelsTimeFormat = "dd/MM\nHH:mm.ss";
//Convert DateTime values to axis values
DateTime now = DateTime.Now;
double minX = xAxis.DateTimeToAxisValue(now);
double maxX = xAxis.DateTimeToAxisValue(now) + 30;
xAxis.SetRange(minX, maxX);
chartView.XAxes[0].LabelsAngle = 90;
then, I didn`t work, and tell me:
chart.HorizontalScrollBars[0].Value = _scrollPosition;(System.ArgumentOutOfRangeException)
2. I add point according to timer(1 point per 200ms), if the xAxis is datetime, how could I get the _previousX? I add the following code:
if (_isRealtime == true)
{
// This triggers X axis' RangeChanged event.
chartView.XAxes[0].ScrollPosition = _previousX;
// In "real-time" mode update scroll bar's LargeChange,
// Maximum and Value properties.
HorizontalScrollBar sb = _chart.HorizontalScrollBars[0];
sb.LargeChange = (ulong)((double)_generatedPoints / ((double)_generatedPoints / (_samplingFrequency * _xLength / 10)) + 0.5);
sb.Maximum = (ulong)_generatedPoints - 1;
sb.Value = (ulong)_generatedPoints - sb.LargeChange;
}
else
{
// In "non-real-time" mode update only LargeChange and
// Maximum. Do not update Value so that scroll bar's thumb
// stays in one place.
HorizontalScrollBar sb = _chart.HorizontalScrollBars[0];
sb.LargeChange = (ulong)((double)_generatedPoints / ((double)_generatedPoints / (_samplingFrequency * _xLength / 10)) + 0.5);
sb.Maximum = (ulong)_generatedPoints - 1;
}
but the scrollbar can't work, could you solve them above two problems?
If you can, can you give me a example in order to study?
Thank you !