gpt4 book ai didi

c# - 没有点和不同线条颜色的 wpf 工具包折线图

转载 作者:太空狗 更新时间:2023-10-29 18:16:50 30 4
gpt4 key购买 nike

我有一些图表,我想动态添加不带数据点的 LineSeries,只是带有一些自定义颜色的线条。我发现隐藏数据点的唯一方法是:

Style style = new Style(typeof(LineDataPoint));
style.Setters.Add(new Setter(LineDataPoint.TemplateProperty, null));

var series = new LineSeries()
{
Title = name,
DependentValuePath = "Y",
IndependentValuePath = "X",
ItemsSource = new ObservableCollection<FloatingPoint>(),
DataPointStyle = style,

};

不幸的是,当我这样做时,所有线条都变成黄色,我无法更改它们的颜色。我试着这样做:

Style style = new Style(typeof(LineDataPoint));
style.Setters.Add(new Setter(LineDataPoint.TemplateProperty, null));

SolidColorBrush brush = new SolidColorBrush(Colors.Red);

var series = new LineSeries()
{
Title = name,
DependentValuePath = "Y",
IndependentValuePath = "X",
ItemsSource = new ObservableCollection<FloatingPoint>(),
DataPointStyle = style,
Background = brush,

};

但这无济于事-我无法更改线条颜色...即使我写了

series.Background = brush;

最佳答案

试试这个。

                    series = new LineSeries();
Style dataPointStyle = GetNewDataPointStyle();
series.DataPointStyle = dataPointStyle;




/// <summary>
/// Gets the new data point style.
/// </summary>
/// <returns></returns>
private static Style GetNewDataPointStyle()
{
Color background = Color.FromRgb((byte)random.Next(255),
(byte)random.Next(255),
(byte)random.Next(255));
Style style = new Style(typeof(DataPoint));
Setter st1 = new Setter(DataPoint.BackgroundProperty,
new SolidColorBrush(background));
Setter st2 = new Setter(DataPoint.BorderBrushProperty,
new SolidColorBrush(Colors.White));
Setter st3 = new Setter(DataPoint.BorderThicknessProperty, new Thickness(0.1));

Setter st4 = new Setter(DataPoint.TemplateProperty, null);
style.Setters.Add(st1);
style.Setters.Add(st2);
style.Setters.Add(st3);
style.Setters.Add(st4);
return style;
}

关于c# - 没有点和不同线条颜色的 wpf 工具包折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5956564/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com