c# - 将 Mappers.Xy<double> 与垂直系列一起使用时如何访问索引?

标签 c# livecharts

我正在尝试使用基于 double 的垂直系列来理解 Mappers.XY 类。为了测试它,我想用红色填充 Y 轴的所有偶数索引,但 .Fill 似乎只使用 X 值。这是我的代码和结果:

var RedBrush = new SolidColorBrush(Color.FromRgb(238, 83, 80));

Mapper = Mappers.Xy<double>()
    .X((value, index) => value)
    .Y((value, index) => index)
    .Fill(index => index % 2 == 0 ? RedBrush : null)
    .Stroke(index => index % 2 == 0 ? RedBrush : null);

仅当 X 值为偶数时,我才以红色条结束,如下所示: Red X-values我什至将 .Fill 更改为基于值但没有更改。

编辑:我想我已经将问题缩小到使用 .Fill 的默认方法,即:

public CartesianMapper<T> Fill(Func<T, object> predicate);

我认为这使用 double 作为填充的基础,在我的例子中,这将是 X 值。相反,我应该使用 .Fill 的重载,它似乎将索引视为一个 int ...这就是我想要的:

 public CartesianMapper<T> Fill(Func<T, int, object> predicate);

问题是我不确定如何使用它。而不是:

.Fill(index => index % 2 == 0 ? RedBrush : null)

应该是什么?我的 lamda 技能处于新手水平。

***可以忽略的先前文本...

我在这里查看了类型和配置以寻求帮助:https://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration更具体地说,我正在尝试使这两个概念适应我自己的概念:

  1. At Series Collection Level

When you define a Series collection instance you can also pass a default configuration, this configuration overrides the global configuration and will be set only if Series configuration is null:

  var mapper = Mappers.Xy<MyClass>().X(v => v.XProp).Y(v => v.YProp);
  var seriesCollection = new SeriesCollection(mapper);
  myChart.SeriesCollection = seriesCollection;
  1. At a specific series

Finally you can also define a mapper only for a series, this will override the >globally and SeriesCollection configuration:

var mapper = Mappers.Xy<MyClass>().X(v => v.XProp).Y(v => v.YProp);
var pieSeries = new PieSeries(mapper);

问题是示例使用的 ObservablePoints 具有我没有的属性,因为我只是使用 double 。

有谁知道是否可以仅使用 double 来做到这一点?还有其他选择吗?

最佳答案

您需要更改 .Fill 的 lambda 表达式,如下所示:

    var Mapper = Mappers.Xy<double>()
            .X((value, index) => value)
            .Y((value, index) => index)
            .Fill((value, index) => index % 2 == 0 ? RedBrush : null);

出于某种原因,在您的表达式中,lambda 表达式似乎正在计算值 % 2 而不是索引 % 2。

下面是使用映射器的行系列图表的图像: Row series chart

关于c# - 将 Mappers.Xy<double> 与垂直系列一起使用时如何访问索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327269/

相关文章:

c# - 当所有异步方法调用完成时引发事件

c# - 列系列 在 x 轴不同间隔上使用不同颜色填充同一系列?

c# - WinForms Livecharts 图表标题

C# Winforms 实时图表 : Fire Event when rendering of CartesianChart is finished

wpf - LiveCharts WPF 渲染性能不佳

wpf - 如何设置实时图表的标签颜色?

c# - MySQLConnection 在 Visual Studio 中抛出异常

c# - 为什么我不能在 C# 中编写从基类到派生类的隐式运算符?

c# - 测试遗留代码时添加虚拟关键字

C# - 使用 NoSQL (MongoDB) 生成类似 Id 的 "identity"?