简体   繁体   English

.Net MAUI - LiveCharts - LineSeries 中的自定义点颜色

[英].Net MAUI - LiveCharts - Custom point color in LineSeries

I'm using LiveCharts v2 in .net MAUI app.我在 .net MAUI 应用程序中使用 LiveCharts v2。 I need to display temprature using chart and change point color when temperature > 38. In WPF i can use CartesianMapper and LineSeries.Configuration, but in .net MAUI i can't find LineSeries.Configuration.我需要使用图表显示温度并在温度 > 38 时更改点颜色。在 WPF 中我可以使用 CartesianMapper 和 LineSeries.Configuration,但在 .net MAUI 中我找不到 LineSeries.Configuration。 So, how to change point color?那么,如何改变点的颜色呢?

I've tried LineSeries.Mapping, but i don't know how to change ChartPoint color?我尝试过 LineSeries.Mapping,但我不知道如何更改 ChartPoint 颜色? ` `

lineSeries.Mapping = (value, point) =>
                        {
                            if (value > 37)
                            {
                                //lineSeries.DataLabelsPaint = new SolidColorPaint(SKColors.Red);
                            }
                            else
                            {
                                
                            }
                            point.PrimaryValue = value;
                            point.SecondaryValue = point.Context.Entity.EntityIndex;
                            
                        };

` `

LiveCharts2 is based on LiveCharts but the API is a little bit different, this feature is now called ConditionalDraw and while it is not properly documented yet, you can get info about it here . LiveCharts2 基于 LiveCharts,但 API 有点不同,此功能现在称为ConditionalDraw ,虽然尚未正确记录,但您可以在此处获取相关信息。

// full code at 
// https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/ViewModelsSamples/General/ConditionalDraw/ViewModel.cs
var series1 = new ColumnSeries<ObservableValue>
{
    Name = "Mary",
    Values = new ObservableValue[] { ... }
}
.WithConditionalPaint(new SolidColorPaint(SKColors.Black.WithAlpha(50)))
.When(point => point.Model?.Value > 5);

I think changing the color of the labels is not supported by now, I will take deeper look into that and update the docs.我认为现在不支持更改标签的颜色,我将深入研究并更新文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM