【问题标题】:wpf toolkit line chart without points and with different line colorswpf工具包折线图没有点和不同的线条颜色
【发布时间】:2011-05-10 21:16:09
【问题描述】:

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

【问题讨论】:

    标签: c# wpf wpftoolkit charts


    【解决方案1】:

    试试这个。

                        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;
        }
    

    【讨论】:

    • 这应该是公认的答案。 +1 帮助我解决问题。这也适用于 XAML。
    猜你喜欢
    • 1970-01-01
    • 2019-07-24
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    相关资源
    最近更新 更多