We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

An item with the same key has already been added.

Thread ID:

Created:

Updated:

Platform:

Replies:

121065 Nov 7,2015 11:50 PM UTC Nov 9,2015 06:26 AM UTC Xamarin.Forms 2
loading
Tags: SfChart
Ian Leatherbury
Asked On November 7, 2015 11:50 PM UTC

Trying to add 2 different Series to my line chart and getting the error: A System.ArgumentException was thrown: An item with the same key has already been added.

Here's my XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="tryfsharpforms.ChartPage"
    xmlns:chart="clr-namespace:Syncfusion.SfChart.XForms;assembly=Syncfusion.SfChart.XForms" >
    <ContentPage.Content>
        <chart:SfChart x:Name="CompareChart">

<!--        Primary Axis-->
            <chart:SfChart.PrimaryAxis>
              <chart:CategoryAxis LabelRotationAngle = "-45">
                <chart:CategoryAxis.Title>
                  <chart:ChartAxisTitle Text ="Date"/>
                </chart:CategoryAxis.Title>
              </chart:CategoryAxis>
            </chart:SfChart.PrimaryAxis>

<!--        Secondary Axis-->
            <chart:SfChart.SecondaryAxis>
              <chart:NumericalAxis>
                <chart:NumericalAxis.Title>
                  <chart:ChartAxisTitle Text ="Price"/>
                </chart:NumericalAxis.Title>
              </chart:NumericalAxis>
            </chart:SfChart.SecondaryAxis>
        
<!--            Line Graph-->
      <chart:SfChart.Series>
        <chart:LineSeries StrokeWidth="3" ItemsSource="{Binding StockData1}" XBindingPath="Date" YBindingPath="Close" x:Name="Series1">
          <chart:LineSeries.DataMarker>
            <chart:ChartDataMarker>
              <chart:ChartDataMarker.LabelStyle>
                <chart:DataMarkerLabelStyle Angle ="315"/>
              </chart:ChartDataMarker.LabelStyle>
            </chart:ChartDataMarker>
          </chart:LineSeries.DataMarker>
        </chart:LineSeries>
      </chart:SfChart.Series>

      <chart:SfChart.Series>
        <chart:LineSeries StrokeWidth="3" ItemsSource="{Binding StockData2}" XBindingPath="Date" YBindingPath="Close" x:Name="Series2">
          <chart:LineSeries.DataMarker>
            <chart:ChartDataMarker>
              <chart:ChartDataMarker.LabelStyle>
                <chart:DataMarkerLabelStyle Angle ="315"/>
              </chart:ChartDataMarker.LabelStyle>
            </chart:ChartDataMarker>
          </chart:LineSeries.DataMarker>
        </chart:LineSeries>
      </chart:SfChart.Series>

<!--      End Line Graph-->
    </chart:SfChart>
    </ContentPage.Content>
</ContentPage>

Ian Leatherbury
Replied On November 8, 2015 06:02 AM UTC

Figured it out. They key was to enclose both Series within <chart:SfChart.Series>. e.g.

 <chart:SfChart.Series>
        <chart:LineSeries StrokeWidth="3" ItemsSource="{Binding StockData1}" XBindingPath="Date" YBindingPath="Close" x:Name="Series1">
        <chart:LineSeries StrokeWidth="3" ItemsSource="{Binding StockData2}" XBindingPath="Date" YBindingPath="Close" x:Name="Series1">  
 </chart:SfChart.Series>

Suresh B [Syncfusion]
Replied On November 9, 2015 06:26 AM UTC

Hi lan,

Thanks for using Syncfusion product.

We are glad to know that your issue is resolved. Please get back to us if you need any further assistance.

Thanks for your update.

Regards,
Suresh B

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;