编程语言
首页 > 编程语言> > c#-Oxyplot中断DateTimeAxis系列

c#-Oxyplot中断DateTimeAxis系列

作者:互联网

如何在特定时间点中断意甲,然后从以后继续?
例如,我的日期时间轴为Y,那么数据一直存在到特定日期,然后没有数据,后来又有了数据.我想要的是不对数据连续插入而中断的最后一个数据点进行插值,但是我想停止绘图并在数据仍然存在的情况下继续.

enter image description here

在上面的屏幕截图中,线性斜率是由于缺少数据所致.我要避免的是那条线.我仍然希望所有中断的数据都在同一系列中.

更新:

foreach (var dp in readings)
{
    data.Add(new DateValue {
        Date = dp.Date,
        Temperature = dp.Data.Where(y => y.Cell == c.Number).
                              Select(x => Convert.ToDouble(x.GetType().GetProperty(sensor.PropertyName).GetValue(x, null))).
                              FirstOrDefault() });

    if (lastDate != null && (dp.Date - lastDate).TotalMinutes > 10)
    {
        data.Add(new DateValue
        {
            Date = dp.Date,
            Temperature = double.NaN
        });
        Console.WriteLine("break");
    }

    lastDate = dp.Date;
}
mode1Data.Add(c.Number, data);

解决方法:

添加一个DataPoint.Undefined,在该行中创建一个中断.您还可以设置“断线”的样式(从oxyplot LineSeriesExample.cs中获取的代码示例):

没有数据绑定:

 var model = new PlotModel("Broken line");

 var s1 = new LineSeries
     {
         // If you want to style
         //BrokenLineColor = OxyColors.Gray,
         //BrokenLineThickness = 1,
         //BrokenLineStyle = LineStyle.Dash
         BrokenLineStyle = LineStyle.None
     };

 s1.Points.Add(new DataPoint(0, 26));
 s1.Points.Add(new DataPoint(10, 30));
 s1.Points.Add(DataPoint.Undefined);
 s1.Points.Add(new DataPoint(10, 25));
 s1.Points.Add(new DataPoint(20, 26));
 s1.Points.Add(new DataPoint(25, 36));
 s1.Points.Add(new DataPoint(30, 40));
 s1.Points.Add(DataPoint.Undefined);
 s1.Points.Add(new DataPoint(30, 20));
 s1.Points.Add(new DataPoint(40, 10));
 model.Series.Add(s1);

enter image description here

使用数据绑定:

xaml:

<oxy:Plot x:Name="plot1" Title="Binding ItemsSource" Subtitle="{Binding Subtitle}">
  <oxy:Plot.Series>
    <oxy:LineSeries Title="Maximum" DataFieldX="Time" DataFieldY="Maximum" Color="Red" LineStyle="Solid" StrokeThickness="2" ItemsSource="{Binding Measurements}"/>
  </oxy:Plot.Series>
</oxy:Plot>

模型:

Measurements = new Collection<Measurement>();
int N = 500;
Subtitle = "N = " + N;

var r = new Random(385);
double dy = 0;
double y = 0;
for (int i = 0; i < N; i++)
{
    dy += r.NextDouble() * 2 - 1;
    y += dy;

    // Create a line break
    if (i % 10 == 0)
    {
        Measurements.Add(new Measurement
        {
            Time = double.NaN, // For DateTime put DateTime.MinValue
            Value = double.NaN
        });   
    }
    else
    {
        Measurements.Add(new Measurement
        {
            Time = 2.5 * i / (N - 1),
            Value = y / (N - 1),
        });   
    }
}

结果:
enter image description here

标签:oxyplot,c
来源: https://codeday.me/bug/20191118/2028894.html