Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The real-time graph only shows the data of the last minute on the x-axis, and the VisibleRange property setting is invalid #20

Open
jyj-code opened this issue Jul 12, 2024 · 0 comments

Comments

@jyj-code
Copy link

The real-time graph only shows the data of the last minute on the x-axis, and the VisibleRange property setting is invalid

private void InitializeChart()
{
    for (int i = 0; i < 50; i++)
    {
        var dataSeries = new XyDataSeries<DateTime, double> { FifoCapacity = 10 };
        Color color = Color.FromArgb(0xAA, (byte)random.Next(1, 256), (byte)random.Next(1, 256), (byte)random.Next(1, 256));
        var lineSeries = new FastLineRenderableSeries()
        {
            DataSeries = dataSeries,
            StrokeThickness = 2,
            Stroke = color
        };
        sciChart.RenderableSeries.Add(lineSeries);
        fastLines.Add(dataSeries);
    }
}

private void StartTimer()
{
var timer = new Timer(1000);
timer.Elapsed += (sender, e) =>
{
Dispatcher.Invoke(() =>
{
var currentDate = DateTime.Now;
for (int i = 0; i < fastLines.Count; i++)
{
var xAxis = sciChart.XAxes.OfType().FirstOrDefault();
if (xAxis != null&& xAxis.DataRange!=null)
{
var newRange = new DateRange(currentDate.AddSeconds(-60), currentDate);

                fastLines[i].XRange.Min = newRange.Min;
                //xAxis.VisibleRange = newRange;
                Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                {
                    xAxis.InvalidateElement();
                }));
                sciChart.ZoomExtents();
            }
            if (fastLines[i].Count > 5 &&i>40)
            {
                break;
            }
            double y = (i + 1);
            fastLines[i].Append(currentDate, y);
        }
    });
};
timer.Start();

}
sciChart
1
2
Uploading SciChartDemo.zip…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant