没有点和不同的线条颜色WPF工具包线图 [英] wpf toolkit line chart without points and with different line colors

查看:480
本文介绍了没有点和不同的线条颜色WPF工具包线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些图表,我想增加动态地检测LineSeries没有数据点,只是一些自定义颜色的线。我发现隐藏的数据点的唯一方法是:



 款式风格=新样式(typeof运算(LineDataPoint)); 
style.Setters.Add(新二传手(LineDataPoint.TemplateProperty,NULL));

VAR系列=新供LineSeries()
{
标题=名称,
DependentValuePath =Y,
IndependentValuePath =X,
的ItemsSource =新的ObservableCollection<&浮点GT;(),
DataPointStyle =风格,

};



不幸的是,当我做到这一点的所有行变成黄色,我不能改变自己的颜色。
我试着这样做:

 款式风格=新样式(typeof运算(LineDataPoint)); 
style.Setters.Add(新二传手(LineDataPoint.TemplateProperty,NULL));

的SolidColorBrush刷=新的SolidColorBrush(Colors.Red);

VAR系列=新供LineSeries()
{
标题=名称,
DependentValuePath =Y,
IndependentValuePath =X,
的ItemsSource =新的ObservableCollection<&浮点GT;(),
DataPointStyle =风格,
=背景刷,

};



但它并不能帮助 - 我不能改变线的颜色......即使我写的

  series.Background =刷; 


解决方案

试试这个。

 系列=新供LineSeries(); 
风格dataPointStyle = GetNewDataPointStyle();
series.DataPointStyle = dataPointStyle;




///<总结>
///获取新的数据点的风格。
///< /总结>
///<&回报GT;< /回报>
私有静态风格GetNewDataPointStyle()
{
色彩背景= Color.FromRgb((字节)random.Next(255),
(字节)random.Next(255)
(字节)random.Next(255));
风格的风格=新样式(typeof运算(数据点));
二传手ST1 =新二传手(DataPoint.BackgroundProperty,
新的SolidColorBrush(背景));
二传手ST2 =新二传手(DataPoint.BorderBrushProperty,
新的SolidColorBrush(Colors.White));
二传手ST3 =新二传手(DataPoint.BorderThicknessProperty,新的厚度(0.1));

二传手ST4 =新二传手(DataPoint.TemplateProperty,NULL);
style.Setters.Add(ST1);
style.Setters.Add(ST2);
style.Setters.Add(ST3);
style.Setters.Add(ST4);
风格的回报;
}


I have some chart and I want to add dynamicly LineSeries without DataPoints, just lines with some custom colors. The only way I found to hide data points is:

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,

        };

Unfortunately when I do this all lines become yellow and I can't change their colors. I tried to do this:

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,

        };

But it doesn't help - I can't change line color... Even if I write

series.Background = brush;

解决方案

Try this.

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

这篇关于没有点和不同的线条颜色WPF工具包线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆