【问题标题】:C# Xamarin bind List to ChartC# Xamarin 将列表绑定到图表
【发布时间】:2018-03-29 10:15:48
【问题描述】:

我创建了一个列表并从列表中选择了 1 个名称,其中包含所有价格和时间戳。

这是我的列表类:

public class price
{
    public string NAME { get; set; }
    public string PRICE { get; set; }
    public string TIMESTAMP { get; set; }
}

这是我选择一些东西的部分:

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();

现在我想将 PRICES 绑定到图表。 我使用 NuGet 包:MicroCharts。这就是您使用该程序创建图表的方式:

PriceChart.Chart = new PointChart { Entries = Source };

如何使用价格作为来源?

完整编辑代码:

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
    });
}

【问题讨论】:

    标签: c# android visual-studio list xamarin


    【解决方案1】:

    你需要根据你的例子创建一个条目数组,如果我理解的话,它应该是这样的

    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
    })
    }
    

    【讨论】:

    • 它在“PRICE and NAME”字样上崩溃,并出现错误:“'IOrderedEnumerable' 不包含 'PRICE' 的定义,并且没有扩展方法 'PRICE' 接受第一个找不到“IOrderedEnumerable”类型的参数(您是否缺少 using 指令或程序集引用?”
    • 好的,我明白了,通过您的过滤器和搜索,您只能得到价格列表,您可以尝试 foreach(var p in singleNameWithOldestPrice) { source.Add(new Entry(p) { Label = "Name" , ValueLabel = p, 颜色 = Color.Red }) }
    • 我在两个“p”上都收到错误:“无法从 Project.price[] 转换为浮点数/字符串”
    • 我不知道 singleNameWithOldestPrice 的确切类型,因为您在 groupe 中提取价格,所以我认为这是一个分组数组!为什么不直接在图表中使用价格,所以你可以从 PriceList foreach(var p in PriceList) 中使用它们
    猜你喜欢
    • 2018-07-06
    • 2019-08-17
    • 2022-01-21
    • 1970-01-01
    • 2023-04-04
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    相关资源
    最近更新 更多