转换列表< double>到LiveCharts.IChartValues [英] Convert List<double> to LiveCharts.IChartValues
本文介绍了转换列表< double>到LiveCharts.IChartValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用LiveCharts在图表中绘制我的double值. 但是我无法转换我的价值观. 我收到错误消息:
I want to plot my double values in a graph with LiveCharts. But I can't convert my values. I get the error:
Cannot convert source type 'System.Collections.Generic.List<double>
to target type 'LiveCharts.IChartValues'
这是我的代码(可能不需要):
This is my code (maybe not needed):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Wpf;
using Brushes = System.Windows.Media.Brushes;
namespace LiveAnalysis
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var xvals = new List<DateTime>();
var yvals = new List<double>();
using (var db = new SystemtestFunctions.TestingContext())
{
var lttResults = db.LttResults;
var par1 = 0.0;
foreach (var data in lttResults)
{
if (data.GatewayEventType == 41)
par1 = data.FloatValue;
if (data.GatewayEventType != 42) continue;
var par2 = data.FloatValue;
var diff = Math.Round(par1 - par2, 3);
yvals.Add(diff);
xvals.Add(data.DateTime);
}
}
cartesianChart1.Series = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = yvals,
},
};
}
}
}
推荐答案
除了@Pikoh的答案外,您还可以使用AsChartValues()
扩展名将任何IEnumerable
转换为ChartValues
实例:
Additionally to @Pikoh's answer, you can also convert any IEnumerable
to a ChartValues
instance, using AsChartValues()
extention:
cartesianChart1.Series = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = yvals.AsChartValues(),
},
};
这篇关于转换列表< double>到LiveCharts.IChartValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文