Hello everybody,
Having two FastLineRenderableSeries objects, how can I display them on the same chart, where the X axis represents the time, but the second one with a small time delay on the x-axis (shifted)? Thanks.
- Marius Cabas asked 3 weeks ago
- You must login to post comments
Hi Marius
This can be achieved with our Filters API.
We already have an Offset filter but this only offsets in the Y-direction.
Offsetting in the X-direction could be achieved by writing a custom filter. For example, try this:
/// To create a custom filter, inherit FilterBase and override FilterALl. For best performance, you can also override FilterOnAppend
/// </summary>
public class OffsetXFilter : FilterBase
{
private readonly XyDataSeries<TimeSpan, double> _originalDataSeries;
private readonly XyDataSeries<TimeSpan, double> _filteredDataSeries = new XyDataSeries<TimeSpan, double>();
public OffsetXFilter(XyDataSeries<TimeSpan, double> originalDataSeries, TimeSpan offset) : base(originalDataSeries)
{
_originalDataSeries = originalDataSeries;
// Store a reference in the base class to the FilteredDataSeries
FilteredDataSeries = _filteredDataSeries;
XOffset = offset;
// Update the filter
FilterAll();
}
public TimeSpan XOffset { get; set; }
protected override void FilterOnAppend(int index)
{
// Override FilterOnAppend to update just the latest data-point in _filteredDataSeries for a more efficient filter
base.FilterOnAppend(index);
}
protected override void FilterOnInsert(int startIndex, int count)
{
// Override FilterOnInsert to update just the inserted data-point in _filteredDataSeries for a more efficient filter
base.FilterOnInsert(startIndex, count);
}
protected override void FilterOnRemove(int startIndex, int count)
{
// Override FilterOnRemove to update just the removed data-point in _filteredDataSeries for a more efficient filter
base.FilterOnRemove(startIndex, count);
}
protected override void FilterOnUpdate(int index)
{
// Override FilterOnUpdate to update just the updated data-point in _filteredDataSeries for a more efficient filter
base.FilterOnUpdate(index);
}
public override void FilterAll()
{
// When FilterAll is called, recreate the FilteredDataSeries and apply the filtering.
_filteredDataSeries.Clear();
for (int i = 0; i < _originalDataSeries.Count; i++)
{
_filteredDataSeries.Append(_originalDataSeries.XValues[i] + XOffset, _originalDataSeries.YValues[i]);
}
}
}
Note: The above is not the most performant solution, as it will update the entire Offset filtered dataseries on every change of the underlying series. For optimal results, consider overriding the other functions like filterOnAppend, filterOnRemove etc
Best regards
Andrew
- Andrew Burnett-Thompson answered 3 weeks ago
- You must login to post comments
Please login first to submit.