繁体   English   中英

wpf toolkit折线图,没有点和不同的线条颜色

[英]wpf toolkit line chart without points and with different line colors

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

暂无
暂无

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

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