1

1)我想在 5 分钟前创建缩放快捷方式。从最后一刻起 10 分钟和 24 小时。

我制作了这段代码,但它不能正常工作。

我应该解决什么问题?

    ZoomOptions = new List<ZoomOption>
    {
        new ZoomOption("5M", TimeSpan.FromMinutes(5)),
        new ZoomOption("30M", TimeSpan.FromMinutes(30)),
        new ZoomOption("1H", TimeSpan.FromHours(1)),
        new ZoomOption("1D", TimeSpan.FromHours(24)),
    };

    SelectedZoomOption = ZoomOptions.Last();

private void UpdateZoom()
{
    if (_viewModel == null ||
        _viewModel.SelectedZoomOption == null ||
        _viewModel.LastTick == null) return;

    var timeSpan = _viewModel.SelectedZoomOption.Time;
    var latestXValue = _viewModel.LastTick.Time;
    var startDate = latestXValue - timeSpan;

    var axis = (CategoryDateTimeAxis)Chart.XAxis;
    if (axis == null || axis.VisibleRange == null) return;
    var calc = (ICategoryCoordinateCalculator)axis.GetCurrentCoordinateCalculator();
    if (calc == null) return;
    var startIndex = calc.TransformDataToIndex(startDate);

    var max = ((IndexRange)axis.VisibleRange).Max;
    var desiredMax = calc.TransformDataToIndex(latestXValue) + 5;
    if (timeSpan < TimeSpan.FromMinutes(10))
    {
        max = desiredMax;
    }
    else if (max == desiredMax)
    {
        max += 100;
    }
    axis.VisibleRange = new IndexRange(startIndex, max);
}

2) 为什么当我没有图表历史但只有新的刻度时,我从一开始就看不到图表,但应该用鼠标回到以前的一点?

3) 更改菜单中的图形以初始化和重置时我应该怎么做?

4

1 回答 1

0

In SciChart when you are using the CategoryDateTimeAxis, one bar (one data-point) = x Minutes (assuming your data is equal spacing per bar).

For instance, if you have 15-minute (900 seconds) bars on the chart, then 10 bars = 150 minutes (9000 seconds). Therefore all you need to do is to set XAxis.VisibleRange as follows:

public void SetRangeToTimeFrame(TimeSpan timeFrame)
{
    // Assuming you have a reference to the data series of type OhlcDataSeries
    int indexMax = dataSeries.XValues.Count - 1;

    // Assuming you know timeframe (one bar = X seconds)
    // If you don;t know this, SciChart tries to calculate it in the 
    // CategoryDateTimeAxis.BarTimeFrame property
    const int timeframe = 900; // for example 900 seconds per bar

    // Calculate the min index to display. Do not go below zero
    int indexMin = Math.Max(indexMax - (timeFrame.TotalSeconds / timeFrame), 0);

    // Set XAxis.VisibleRange equal to the new range
    // OR, Set via binding if you have a property XVisibleRange in ViewModel
    XAxis.VisibleRange = new IndexRange(indexMin, indexMax);
}

That really is it!

If you have variable length bars (e.g. one bar is 10 minutes, one is 20 seconds) then your calculation becomes near impossible ... but it is still possible. Let me know if this is the case, I will improve the answer.

(2) and (3) are really different questions and need more clarification before they can be answered.

Disclaimer: I am the tech lead of the SciChart WPF Project

于 2016-03-30T09:22:24.867 回答