Oxyplot中断DateTimeAxis系列

时间:2016-06-14 10:06:45

标签: c# oxyplot

如何在某个时刻打断系列,然后从以后的位置继续? 例如,我将日期时间轴设为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);

1 个答案:

答案 0 :(得分:3)

添加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