Type of the Item in the C1ChartLegend.ItemTemplate?

Posted by: wkelly1 on 3 August 2018, 12:48 am EST

  • Posted 3 August 2018, 12:48 am EST


    I need to customize the legend of the C1Chart. The customer would like a check box to appear adjacent to each item. He would like to be able to turn the associated data series on and off.

    Current Approach

    I have tried customizing the legend's ItemTemplate.

    <CheckBox Content="{Binding}" />

    That results in the following:

    I'm assuming that the "{Binding}" on the Checkbox's Content property is displaying the ToString() method of the item being bound.

    Now, I need to display the color/dash/thickness of the associated data series. I am using XYDataSeries.


    Is there a better way to accomplish this? Better than providing an ItemTemplate?

    What is the type of the object being bound in the ItemTemplate? Is it the associated Series? Is it the Label of the Series?
  • Replied 3 August 2018, 1:24 am EST

    I think I just found the answer to my second question, LegendItem:


  • Marked as Answer

    Replied 5 August 2018, 11:13 pm EST


    For your 1st question, I think using ItemTemplate is the better and easier option to have custom controls for legend items.

    As for your second question, you are right that LegendItem is bound to ItemTemplate. So, you can directly use LegendItem.Symbol/LegendItem.Line for displaying shapes of symbols and connection lines. Please refer the attached sample(prj_CustomLegends.zip) for doing so.

    Thank you.
  • Replied 13 August 2018, 11:46 pm EST

    For those using MVVM and data binding, you might need to know that LegendItem's Item property does not store the instances of the ChartData's SeriesItemsSource, as one might expect. Instead, the LegendItem.Item stores a references to the DataSeries (which you are likely defining in a DataTemplate). To get access to the item provided by the SeriesItemSource, you can store the item in the Tag property of the DataSeries.

    Here is my code. Notice how the Tag property is used.

    <c1:ChartData DataContext="{Binding NotifyOnTargetUpdated=True}" SeriesItemsSource="{Binding ChartSeriesData}">
    ItemsSource="{Binding Points}"
    Label="{Binding Label}"
    ValueBinding="{Binding Y}"
    Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"
    XValueBinding="{Binding X}" />
    <StackPanel Orientation="Horizontal">
    Content="{Binding Label}"
    IsChecked="{Binding Item.Tag.IsVisible}" />
    Content="{Binding Line}" />
    Content="{Binding Symbol}" />

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels