Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

.net - Updating LiveCharts legend series colours when series colour set by CartesianMapper lambda expression

I have a LiveCharts graph with a series and a mapper which changes the series Fill based on if the value exceeds a specified value:

Dim Mapper As CartesianMapper(Of Double) = Mappers.Xy(Of Double)
Mapper.X(Function(value, index) index)
Mapper.Y(Function(value, index) value)
Mapper.Fill(Function(value, index)
                Return If(value > Tolerance,
                    New SolidColorBrush(Color.FromArgb(red.A, red.R, red.G, red.B)),
                    New SolidColorBrush(Color.FromArgb(cyan.A, cyan.R, cyan.G, cyan.B)))
            End Function)

Dim PercentageSeries As New ColumnSeries With {
    .Title = "% Difference",
    .ColumnPadding = 1,
    .Fill = New SolidColorBrush(Color.FromArgb(cyan.A, cyan.R, cyan.G, cyan.B)),
    .Values = New ChartValues(Of Double)(PercentageValues),
    .ScalesYAt = 1,
    .Configuration = Mapper
}

This works to correctly change the series colour:

correct legend series colour

What it doesn't do correctly is update the series colour in the legend when the series colour is changed based on the Mapper:

incorrect legend series colour

Note that the PercentageSeries series should be the orange colour in the legend.

Removing the default Fill from the PercentageSeries also has the same result, except that the legend series uses LiveChart's default yellow colour for everything.

I've looked at the documentation for LiveCharts and I've seen that I can replace the DefaultLegend but I can't see where or how I could have the series colours also change based on the Mapper I've created.

question from:https://stackoverflow.com/questions/65885924/updating-livecharts-legend-series-colours-when-series-colour-set-by-cartesianmap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...