2015-01-15 3 views
1

XAML을 통해 HighLowSeries을 정의하고 싶습니다. HighLowSeries-graphs 사용할 수없는 때문에 oxyplot.wpf 네임 스페이스에 내가 다음 클래스 만들었습니다 윈도우의 뒤에 코드에서Xaml oxyplot HighLowSeries Items 바인딩

<Window x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Oxy="http://oxyplot.org/wpf" 
    xmlns:Tmp="clr-namespace:WpfApplication1" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <Oxy:PlotView Width="300" 
        Height="300" 
        Title="Test"> 
     <Oxy:PlotView.Series> 
      <Tmp:HighLowSeries ItemsSource="{Binding list}" /> 
     </Oxy:PlotView.Series> 
    </Oxy:PlotView> 
</Grid> 
</Window> 

: 내 창에서

public class HighLowSeries : OxyPlot.Wpf.XYAxisSeries 
{ 

    public HighLowSeries() 
    { 
     this.InternalSeries = new OxyPlot.Series.HighLowSeries(); 
    } 

    public override OxyPlot.Series.Series CreateModel() 
    { 
     this.SynchronizeProperties(this.InternalSeries); 
     return this.InternalSeries; 
    } 

    /// <summary> 
    /// The synchronize properties. 
    /// </summary> 
    /// <param name="series"> 
    /// The series. 
    /// </param> 
    protected override void SynchronizeProperties(OxyPlot.Series.Series series) 
    { 
     base.SynchronizeProperties(series); 
     var s = (OxyPlot.Series.HighLowSeries)series; 

     foreach (HighLowItem item in s.Items) 
     { 
      Trace.WriteLine("HighLowSeries " + item.X); 
     } 

    } 

} 

을, 나는 HighLowSeries는 다음과 같은 방법을 사용 나는 (0,0)에서만 작은 수평선이 응용 프로그램을 시작할 때

 private IList<HighLowItem> _list; 

    public IList<HighLowItem> list 
    { 
     get 
     { 
      return this._list; 
     } 
     set 
     { 
      this._list = value; 
     } 
    } 

    public MainWindow() 
    { 
     this.list = new List<HighLowItem>(); 

     list.Add(new HighLowItem(10, 8, 3, 2, 5)); 
     list.Add(new HighLowItem(12, 7, 4, 4, 2)); 
     list.Add(new HighLowItem(18, 4, 1, 2, 3)); 

     this.DataContext = this; 

     InitializeComponent(); 
    } 

: 나는 다음과 같은 코드가,HighLowSeries

는 또한 내가 항목-컬렉션에 HighLowElements의 X 좌표를 출력 HighLowSeries.SynchronizeProperties()Trace.WriteLine있다. 출력의 양은 list-property의 요소와 일치합니다 (MainWindow). 그러나 X 좌표는 항상 0입니다 (HighLowElements의 다른 속성뿐 아니라). 동일한 방법으로 직접 LineSeries을 구현하면 모든 것이 제대로 작동합니다.

이것은 oxyplot의 버그입니까? 또는 나는 무엇인가 놓치고있다? 현재 코드를 통해 HighLowSeries을 생성하는 것은 옵션이 아닙니다.

답변

2

마지막으로 자리가 발견되어 DataPoints의 목록이 지워집니다. 소스 코드 (OxyPlot Source HighLowItemSeries)

에서

이 방법이 있습니다 :

/// <summary> 
/// Updates the data. 
/// </summary> 
protected internal override void UpdateData() 
{ 
    if (this.ItemsSource == null) 
    { 
     return; 
    } 

    this.items.Clear(); 

    // Use the mapping to generate the points 
    if (this.Mapping != null) 
    { 
     foreach (var item in this.ItemsSource) 
     { 
      this.items.Add(this.Mapping(item)); 
     } 
     return; 
    } 

    var filler = new ListFiller<HighLowItem>(); 
    filler.Add(this.DataFieldX, (p, v) => p.X = Axis.ToDouble(v)); 
    filler.Add(this.DataFieldHigh, (p, v) => p.High = Axis.ToDouble(v)); 
    filler.Add(this.DataFieldLow, (p, v) => p.Low = Axis.ToDouble(v)); 
    filler.Add(this.DataFieldOpen, (p, v) => p.Open = Axis.ToDouble(v)); 
    filler.Add(this.DataFieldClose, (p, v) => p.Close = Axis.ToDouble(v)); 
    filler.FillT(this.items, this.ItemsSource); 
} 

때문에 this.Mapping가 null 동일의 mapping이 무시되고 filler object이 추가됩니다

Mapping-field의 코멘트. 값을 설정하는 방법을 알려줍니다.

/// <summary> 
    /// Gets or sets the mapping delegate. 
    /// </summary> 
    /// <value>The mapping.</value> 
    /// <remarks>Example: series1.Mapping = item => new HighLowItem(((MyType)item).Time,((MyType)item).Value);</remarks> 
    public Func<object, HighLowItem> Mapping { get; set; } 

SynchronizeProperties 메서드를 다음과 같이 변경하면 모든 작업이 올바르게 수행됩니다.

protected override void SynchronizeProperties(OxyPlot.Series.Series series) 
    { 
     base.SynchronizeProperties(series); 
     var s = (OxyPlot.Series.HighLowSeries)series; 
     s.Mapping = item => new HighLowItem(((HighLowItem)item).X, ((HighLowItem)item).High, ((HighLowItem)item).Low, ((HighLowItem)item).Open, ((HighLowItem)item).Close); 
    }