使用Live Charts功能对比多条折线时当Label不是一一对应时会发现折线无法对比如
Labels =
List<double> list2 = new List<double>();
list2.Add(2.1); //x为0.5时
list2.Add(2.2); //x为0.6时
list2.Add(2.3); //x为0.7时
list2.Add(2.4); //x为0.8时
list2.Add(2.5); //x为0.9时
list2.Add(2.6); //x为10.0时
list2.Add(2.7); //x为10.1时
List<double> list3 = new List<double>();
list3.Add(3.1); //x为0.55时
list3.Add(3.3); //x为0.65时
list3.Add(3.4); //x为0.75时
list3.Add(7.7); //x为0.95时
SeriesList.Add(new LineSeries()
{
Title = kv.Key,
LineSmoothness = 0,
PointGeometry = DefaultGeometries.Circle,
Values = new ChartValues<double>(list1.Select(x => Double.Parse(x.ToString())).ToList()),
Fill = new SolidColorBrush(Colors.Transparent),
});
SeriesList.Add(new LineSeries()
{
Title = kv.Key,
LineSmoothness = 0,
PointGeometry = DefaultGeometries.Circle,
Values = new ChartValues<double>(list2.Select(x => Double.Parse(x.ToString())).ToList()),
Fill = new SolidColorBrush(Colors.Transparent),
});
发现折线图全是断断续续的
如果想要解决以上问题就需要修改ChartValues类型,由原来的double修改成ObservablePoint
List<LiveCharts.Defaults.ObservablePoint> chartPoint2 = new List<LiveCharts.Defaults.ObservablePoint>();
for (int i = 0; i < 100; i++)
{
if (i % 5 == 0)
{
continue;
}
chartPoint2.Add(new LiveCharts.Defaults.ObservablePoint() { X = i + 1.1, Y = i + 10.1 });
}
List<LiveCharts.Defaults.ObservablePoint> chartPoint3 = new List<LiveCharts.Defaults.ObservablePoint>();
for (int i = 0; i < 100; i++)
{
chartPoint3.Add(new LiveCharts.Defaults.ObservablePoint() { X = i + 1.1, Y = i + 20.1 });
}
SeriesList.Add(new LineSeries()
{
Title = kv.Key,
LineSmoothness = 0,
PointGeometry = DefaultGeometries.Circle,
Values = new ChartValues<LiveCharts.Defaults.ObservablePoint>(chartPoint2),
Fill = new SolidColorBrush(Colors.Transparent),
}); ;
SeriesList.Add(new LineSeries()
{
Title = kv.Key,
LineSmoothness = 0,
PointGeometry = DefaultGeometries.Circle,
Values = new ChartValues<LiveCharts.Defaults.ObservablePoint>(chartPoint3),
Fill = new SolidColorBrush(Colors.Transparent),
}); 文章来源:https://www.toymoban.com/news/detail-419593.html
即可解决上述问题文章来源地址https://www.toymoban.com/news/detail-419593.html
到了这里,关于WPF 控件库Live Charts 折线图多折线比较问题处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!