I'm using the C# library "LiveCharts" in my Winforms project. I'm trying to draw a regular line series on top of a few Stacked Area Series, and wondering if it is possible to do.
Here is my code:
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;
I'm trying to make the "GoalLine" always appear infront of the other series, but seems to always be drawn behind. Is there a property I can define that controls the draw order of these series?
Here's a picture of how this graph is being drawn in my application.
CodePudding user response:
Here is someone that seems to be having the same issue that you are having:
https://github.com/Live-Charts/Live-Charts/issues/231
You will most likely need to set the ZIndex of the line series so that it is displayed on top.