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

标签 c# wpf wpftoolkit charts

我有一些图表,我想动态添加不带数据点的 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/

相关文章:

javascript - jQuery 数据表 : Heading and Search on the same line

c# - Facebook API 入门

WPF IsEditable=true 填充对象的 ComboBox 将 ToString() 显示为所选项目

wpf - 根本原因 : Recursive call to Automation Peer API is not valid

c# - 重试 Azure 表中的批量操作

c# - 在 KeyValuePair/Dictionary 中重命名键/值

c# - 在 Simple Injector 中注册时设置收集项目的 Lifestyle

c# - 有没有办法为 EF 模型自动创建 CRUD(目前是 DB First)

wpf - 结束日期不能小于开始日期 (WPFToolkit DatePicker)

c# - WPFToolkit 数据网格 : Highlight modified rows