SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

0
0

I have two AxisCollections:

private AxisCollection _xAxes = new AxisCollection();
public AxisCollection XAxes
{
    get => _xAxes;
    set 
    {
        _xAxes = value;
        OnPropertyChanged("XAxes");
    }
}

private AxisCollection _yAxes = new AxisCollection();
public AxisCollection YAxes
{
    get => _yAxes;
    set
    {
        _yAxes = value;
        OnPropertyChanged("YAxes");
    }
}

Both are binded to XAxes and YAxes of SciChartSurface respectively:

   <s:SciChartSurface Grid.Row="0"
                   Grid.RowSpan="3"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   Panel.ZIndex="0"
                   RenderableSeries="{Binding RenderableSeries}"  
                   ChartTitle="{Binding ChartTitle}"
                   XAxes="{Binding XAxes}"
                   YAxes="{Binding YAxes}">

I try to add axes using following method:

    public void AddAxes()
{
    XAxes.Add(new NumericAxis() { AxisTitle = "X Achse"});
    XAxes.Add(new NumericAxis() { AxisTitle = "X Achse 2" });
    YAxes.Add(new NumericAxis() { AxisTitle = "Y Achse", AxisAlignment = AxisAlignment.Left});
}

Addition of a second X axis causes an exception:

“SciChartSurface didn’t render, because an exception was thrown: Message: Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt.”

what means “An item with the same key has already been added”. I assume (though not sure) it happens because all of the created axes have the same x:Key attribute.

How can I fix this issue?

Version
3.3
  • You must to post comments
0
0

Addition of unique Id solves this:

        public void AddAxes()
        {
            XAxes.Add(new NumericAxis() { Id = "1", AxisTitle = "X Achse"});
            XAxes.Add(new NumericAxis() { Id = "2", AxisTitle = "X Achse 2" });
            YAxes.Add(new NumericAxis() { AxisTitle = "Y Achse", AxisAlignment = AxisAlignment.Left});
        }
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.