在垂直系列中使用 Mappers.Xy<double> 时如何访问索引?

How to access index when using Mappers.Xy<double> with vertical Series?

我正在尝试使用基于双打的垂直系列来理解 Mappers.XY class。为了测试它,我想用红色填充 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 具有我没有的属性,因为我只是使用双打。

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

您需要更改 .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。

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