使用 Livecharts,有没有办法订购哪些图表系列绘制在其他图表系列之上?

Using Livecharts, is there a way to order which Chart Series are drawn on top of others?

我在我的 Winforms 项目中使用 C# 库“LiveCharts”。 我正在尝试在几个堆叠区域系列之上绘制一个规则的线系列,想知道是否可以这样做。

这是我的代码:

mainChart.Series = new SeriesCollection
{          
    new StackedAreaSeries
    {
        Title = "Account1",
        Values = new ChartValues<DateTimePoint>
        {
            new DateTimePoint(new System.DateTime(2022, 1, 1), 2000.5),
            new DateTimePoint(new System.DateTime(2022, 1, 2), 2030.85),
            new DateTimePoint(new System.DateTime(2022, 1, 3), 2030.48),
            new DateTimePoint(new System.DateTime(2022, 1, 4), 2031.30),
            new DateTimePoint(new System.DateTime(2022, 1, 5), 2035.08),
            new DateTimePoint(new System.DateTime(2022, 1, 6), 2030.56),
            new DateTimePoint(new System.DateTime(2022, 1, 7), 2029.56),
            new DateTimePoint(new System.DateTime(2022, 1, 8), 2031)
        },
        LineSmoothness = 1,
        //Fill = brush1
    },
    new StackedAreaSeries
    {
        Title = "Account2",
        Values = new ChartValues<DateTimePoint>
        {
            new DateTimePoint(new System.DateTime(2022, 1, 1), 300),
            new DateTimePoint(new System.DateTime(2022, 1, 2), 300),
            new DateTimePoint(new System.DateTime(2022, 1, 3), 300),
            new DateTimePoint(new System.DateTime(2022, 1, 4), 300),
            new DateTimePoint(new System.DateTime(2022, 1, 5), 301),
            new DateTimePoint(new System.DateTime(2022, 1, 6), 302.67),
            new DateTimePoint(new System.DateTime(2022, 1, 7), 280),
            new DateTimePoint(new System.DateTime(2022, 1, 8), 305)
        },
        LineSmoothness = 1
    },
    new StackedAreaSeries
    {
        Title = "Account3",
        Values = new ChartValues<DateTimePoint>
        {
            new DateTimePoint(new System.DateTime(2022, 1, 1), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 2), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 3), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 4), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 5), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 6), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 7), 200),
            new DateTimePoint(new System.DateTime(2022, 1, 8), 200)
        },
        LineSmoothness = 1
    }
};
mainChart.Series.Add(
    new LineSeries
    {
        Title = "GoalLine",
        Values = new ChartValues<DateTimePoint>
        {
            new DateTimePoint(new System.DateTime(2022, 1, 1), 1500),
            new DateTimePoint(new System.DateTime(2022, 1, 2), 1525),
            new DateTimePoint(new System.DateTime(2022, 1, 3), 1550),
            new DateTimePoint(new System.DateTime(2022, 1, 4), 1575),
            new DateTimePoint(new System.DateTime(2022, 1, 5), 1600),
            new DateTimePoint(new System.DateTime(2022, 1, 6), 1625),
            new DateTimePoint(new System.DateTime(2022, 1, 7), 1650),
            new DateTimePoint(new System.DateTime(2022, 1, 8), 1675)
        },
        LineSmoothness = 1
    }
    );
mainChart.AxisX.Add(new Axis
{
    LabelFormatter = val => new System.DateTime((long)val).ToString("yyyy-MM-dd")
});
mainChart.AxisY.Add(new Axis
{
    LabelFormatter = val => val.ToString("c")
});
mainChart.LegendLocation = LegendLocation.Right;
mainChart.DefaultLegend.Visibility = Visibility.Visible;

我试图让“GoalLine”总是出现在其他系列的前面,但似乎总是被拉到后面。是否有 属性 我可以定义控制这些系列的绘制顺序?

Here's a picture of how this graph is being drawn in my application.

有人似乎遇到了与您同样的问题:

https://github.com/Live-Charts/Live-Charts/issues/231

您很可能需要设置线系列的 ZIndex 以使其显示在顶部。