我在使用LiveCharts时遇到了一些问题。我将向系列集合添加实时数据。
这是我的Xaml:
<lvc:CartesianChart DisableAnimations="True"
Hoverable="False"
DataTooltip="{x:Null}"
Series="{Binding Series}"
Zoom="Xy"
Width="1300"
/>
.我创建了一个意甲属性:
private SeriesCollection series;
public SeriesCollection Series
{
get { return series; }
set { SetProperty(ref series, value, "Series"); }
}
在构造函数中初始化了它:
Series = new SeriesCollection();
Series.Add(new GLineSeries()
{
Name = debugChannelSelected.Name.Replace(' ', '_'),
Title = debugChannelSelected.Name,
Stroke = (Brush)new BrushConverter().ConvertFromString(debugChannelSelected.Color),
Values = new GearedValues<double>(),
Fill = Brushes.Transparent,
PointGeometry = null
});
}
debugChannelSelected 由 Messenger 接收。
每隔 100 毫秒,我将在我的系列中添加一个新的双倍:
for (var j = 0; j < SelectedChannels.Count(); j++)
{
if (SelectedChannels[j] != null)
{
var serie =
Series.FirstOrDefault(w => w.Title.Equals(SelectedChannels[j]));
for (var i = 0; i < dataSize; i++)
{
var dbt = Convert.ToDouble(rnd.Next(-1000, 10000));
if (serie != null)
{
dbtValues[i] = dbt;
serie.Values.Add(dbt);
if (IsContinuousAcquisition && serie.Values.Count > 1000)
{
serie.Values.RemoveAt(0);
}
}
var dbtGear = dbtValues.AsGearedValues();
serie.Values.AddRange(dbtValues);
}
else
break;
}
但我在意甲中遇到了投射错误。Values.AddRange(dbtValues);.您对如何解决它有任何建议吗?
蒂亚。
我已经更改了Series.Add方法,如下所示:
Series.Add(new GLineSeries()
{
Name = debugChannelSelected.Name.Replace(' ', '_'),
Title = debugChannelSelected.Name,
Stroke = (Brush)new BrushConverter().ConvertFromString(debugChannelSelected.Color),
Values = new ChartValues<ObservableValue>(),
Fill = Brushes.Transparent,
PointGeometry = null
});
现在我可以使用AddRange了。