Oxyplot 中断 DateTimeAxis 系列
Oxyplot to interrupt DateTimeAxis serie
我怎样才能在某个时刻中断 serie,然后从后面的时刻继续?
例如,我的日期时间轴为 Y,然后数据一直存在到某个日期,然后没有数据,稍后我又有数据。我想要的不是插入数据被连续中断的最后一个数据点,而是我想停止绘图并在数据仍然存在时继续。
在上面的屏幕截图中,线性斜率是由于缺少数据造成的。我想要的是避免那条线。我仍然希望所有中断的数据都在同一个系列中。
更新:
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
,在行中创建一个中断。您还可以设置 "broken line" 的样式(取自 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);
有数据绑定:
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),
});
}
}
结果:
我怎样才能在某个时刻中断 serie,然后从后面的时刻继续? 例如,我的日期时间轴为 Y,然后数据一直存在到某个日期,然后没有数据,稍后我又有数据。我想要的不是插入数据被连续中断的最后一个数据点,而是我想停止绘图并在数据仍然存在时继续。
在上面的屏幕截图中,线性斜率是由于缺少数据造成的。我想要的是避免那条线。我仍然希望所有中断的数据都在同一个系列中。
更新:
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
,在行中创建一个中断。您还可以设置 "broken line" 的样式(取自 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);
有数据绑定:
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),
});
}
}
结果: