Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Xamchart legend and label issue
posted

Hi

I am using Infragistics 11.2 xamchart control.The propblem  I am facing is

In my model i have something like this

public

double

XValue

{

get

{

return

m_xValue;

}

set

{

m_xValue =

value

;

OnPropertyChanged(

"XValue"

);

}

}

public double

YValue

{

get

{

return

m_yValue;

}

set

{

m_yValue =

value

;

OnPropertyChanged(

"YValue"

);

}

}

public string

Label

{

get

{

return

m_label;

}

set

{

m_label =

value

;

OnPropertyChanged(

"Label"

);

}

}

In my view model i have

public

ObservableCollection<Model

> _MyProperty;

public IEnumerable<Model

> MyPropertyA

{

get { return _MyProperty.Where<Model>(s => s.Label == "A"

); }

}

public IEnumerable<Model

> MyPropertyB

{

get { return _MyProperty.Where<Model>(s => s.Label == "B"

); }

}

 

 

 

public

ViewModel()

{

_MyProperty=

new ObservableCollection<Model

>


 


 


 

new Model{YValue=1000,XValue=.1,Label = "A"

},

new Model{YValue=1000,XValue=.1,Label = "B"

},

new Model{YValue=2000,XValue=.2,Label = "A"

},

new Model{YValue=4000,XValue=.2,Label = "B"

},

new Model{YValue=3000,XValue=.3,Label = "A"

},

new Model{YValue=6000,XValue=.3,Label = "B"

},

new Model{YValue=4000,XValue=.4,Label = "A"

},

new Model{YValue=9000,XValue=.4,Label = "B"

},

};

}

}

Now in xaml i am binding the series  like this

<igCA:XamChart.Series

>

<igCA:Series ChartType="ScatterLine" DataSource="{Binding MyPropertyA}" DataMapping="ValueX=XValue; ValueY=YValue" Label="{Binding Label

}" >

<igCA:Series.Marker

>

<igCA:Marker Foreground="{Binding Fill}"></igCA:Marker

>

</igCA:Series.Marker

>

</igCA:Series

>

<igCA:Series ChartType="ScatterLine" DataSource="{Binding MyPropertyB}" DataMapping="ValueX=XValue;ValueY=YValue" Label="{Binding Label

}">

<igCA:Series.Marker

>

<igCA:Marker Foreground="{Binding Fill}" ></igCA:Marker

>

</igCA:Series.Marker

>

</igCA:Series

>

</igCA:XamChart.Series

>

The chart gets plotted fine but the problem is that in the legend instead of A and B item 0 and item 1 is coming .Please help what can i do about it.

Also if i have suppose 4 series and each gets generated only when user gives some input for them through a grid or something, is it possible to show the legend for only the series that have been generated.

Thanks in advance


 

Parents
  • 30945
    Offline posted

    Hello,

     

    Thank you for your post. I have been looking into it and if I understand correctly, the issue that you are having is that the text for the items in the Legend is not “A” for the first series and “B” for the second.  The reason for the text in the legend to not display those values is that you are setting the Label property of the Series to Binding with path Label and since your view model (which is the DataContext for the Window and the Series) the XamChart is displaying the default values in the Legend. I assume that you wish to display the Label of the items in the corresponding collection that is used as DataSource for the Series. To do that you can bind the Label property of the series to the Label property of the first item of the DataSource.

     

    Regarding the functionality that you have described, for not showing item in the Legend, if the series does not contain data, I can suggest using XamDataChart, instead of the XamChart. The Series in the XamDataChart, provides a property called LegendItemVisibility, that can be used in order to show or hide the legend item for a series. You can bind the LegendItemVisibility property of the Series, to the Count of property of the ItemsSource and using a converter to return Visible if the count is bigger than 0 and Collapsed if it is not. The XamDataGrid is providing more accurate control over its elements and also better performance and since the XamChart control is already retired  (you can read more detailed information here: http://ko.infragistics.com/community/blogs/jason_beres/archive/2011/11/10/important-product-changes-and-control-retirements-in-2011-2.aspx), I can suggest using XamDataChart. I have create a sample application for you, that demonstrates how you can implement the approach I have mentioned.

     

    Please let me know if you need any further assistance on the matter.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    LegendItems.zip
Reply Children