How to add a HorizontalScrollBar if xAxis is datatime?

A forum dedicated to WPF version of LightningChart Ultimate.

How to add a HorizontalScrollBar if xAxis is datatime?

Postby coldsun1982 » 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 !
coldsun1982
 
Posts: 3
Joined: Thu Feb 28, 2019 1:57 am

Re: How to add a HorizontalScrollBar if xAxis is datatime?

Postby ArctionKestutis » Thu Feb 28, 2019 12:14 pm

Hello,

The first problem is most likely due to HorizontalScrollBar object not being create or not added to Chart.HorizontalScrollBars collection.
Code: Select all
chart.HorizontalScrollBars[0].Value = _scrollPosition;(System.ArgumentOutOfRangeException)


Changing Axis.ValueType should not change any fundamentals of Chart rendering. If you would make xAxis modifications in our Demo example "Historic data review" like in your code, it will work just fine (maybe just add _xLength = 30.0 for consistency). Internally Axis value is maintain in seconds and Axes.ScrollPosition is asking for X-Axis value. Therefore, you should use converter methods, like in this is case xAxes.DateTimeToAxisValue().
Axes.ScrollPosition is the x-value of your last point (you just added).

Hope this helps.
If it is still unclear, please send your project files to Support email (include the subscriptionID or information about yourself).
ArctionKestutis
 
Posts: 353
Joined: Mon Mar 14, 2016 9:22 am


Return to LightningChart Ultimate WPF

Who is online

Users browsing this forum: No registered users and 2 guests

cron