[英]C# Xamarin bind List to Chart
I created a List and selected 1 Name from the List with all the Prices and Timestamps. 我创建了一个列表,并从列表中选择了1个名称以及所有价格和时间戳。
This is my List Class: 这是我的列表类:
public class price
{
public string NAME { get; set; }
public string PRICE { get; set; }
public string TIMESTAMP { get; set; }
}
And this is the part where I select a few things: 这是我选择一些内容的部分:
var singleNameWithOldestPrice =
from p in PriceList
where p.NAME.Contains(SelectedProduct, StringComparison.OrdinalIgnoreCase)
group p by p.NAME into grp
select grp.OrderBy(a => a.TIMESTAMP).ToArray();
Now I want to bind the PRICES to the Chart. 现在,我想将价格绑定到图表。 I use the NuGet Package: MicroCharts.
我使用了NuGet软件包:MicroCharts。 This is how you create a chart with that program:
这是您使用该程序创建图表的方式:
PriceChart.Chart = new PointChart { Entries = Source };
How can I use the Prices as Source? 如何使用价格作为来源?
FULL EDITED CODE: 完整的代码:
var singleNameWithOldestPrice =
from p in PriceList
where p.NAME.Contains(SelectedProduct, StringComparison.OrdinalIgnoreCase)
group p by p.NAME into grp
select grp.OrderBy(a => a.TIMESTAMP).ToArray();
var source = new List<Entry>();
foreach (var p in singleNameWithOldestPrice)
{
source.Add(new Entry(p.PRICE)
{
Label = p.NAME,
ValueLabel = p.PRICE,
Color = Color.Red
});
}
you need to create an array of entries , based on your example if i well understand , it should be smth like this 您需要根据您的示例创建一个条目数组,如果我很好理解,应该像这样
var source = new List<Entry>();
foreach(var p in singleNameWithOldestPrice )
{
source.Add(new Entry(p)
{
Label = "name of every label",
ValueLabel = p,
Color = Color.Red
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.