2011-05-10 12 views
8

Tengo un gráfico y quiero agregar LineSeries dinámicamente sin DataPoints, solo líneas con algunos colores personalizados. La única manera que he encontrado para ocultar los puntos de datos es:wpf toolkit gráfico de líneas sin puntos y con diferentes colores de línea

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, 

     }; 

Desafortunadamente cuando hago esto todas las líneas se vuelven de color amarillo y no puede cambiar sus colores. he tratado de hacer esto:

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, 

     }; 

Pero no ayuda - No puedo cambiar el color de línea ... Incluso si escribo

series.Background = brush; 

Respuesta

15

probar esto.

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

+1 Awesome! ¡Muchas gracias! – Legend

+0

esta debería ser la respuesta aceptada. +1 por ayudarme a resolver el problema. Esto también funciona en XAML. –

Cuestiones relacionadas