2011-05-10 29 views
8

Bazı grafikler var ve bazı özel renklere sahip satırlar DataPoints olmadan dinamik olarak LineSeries eklemek istiyorum. Ben veri noktalarını gizlemek için bulunan tek yoludur: yaptığımdawpf toolkit hat şeması nokta olmadan ve farklı çizgi renkleriyle

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, 

     }; 

Ne yazık ki bu tüm hatlar sarı olur ve onların renklerini değiştirmek mümkün değil.

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, 

     }; 

Ama yardımcı olmuyor - Ben çizgi rengini değiştiremez ...

series.Background = brush; 

cevap

15

bu deneyin yazıyorum bile: Bunu yapmaya çalıştım.

    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! Çok teşekkürler! – Legend

+0

bu kabul edilen cevap olmalıdır. Sorunu çözmeme yardımcı olmak için +1. Bu da XAML'de çalışır. –