wpf toolkit line chart without points and with different line colors
10,491
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;
}
Related videos on Youtube
Author by
user606521
Updated on June 04, 2022Comments
-
user606521 almost 2 years
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;
-
Scott M. about 12 yearsthis should be the accepted answer. +1 for helping me solve the problem. This works in XAML as well.