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
645
Custom series markers in legend
posted

My xamDataChart displays a number of ScatterSeries and I build a set of custom markers to display on my xamDataChart and would like to get those to show up in the legend.  To get the custom markers to show up I essentially created the marker points (e.g., for a square I might do "0,0 1,0 1,1 0,1") and created a polygon template like so:

 

<DataTemplate x:Key="polygonTemplate">

   <Polygon Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"

      Fill="{Binding ActualItemBrush}" Points = "{Binding Item.Points}" Stroke="{Binding Series.ActualMarkerOutline}"

      MinWidth="10" MinHeight="10" RenderTransform="{Binding Item.RenderTransform}"/>

</DataTemplate>

In the code behind, I build my scatter series.

This works pretty well but my legend doesn't display the polygon badge (I think that's what it is called).  

If I create instead an ellipseTemplate which uses an Ellipse, it'll draw pretty well (since I didn't have to bind it to something to get the points that make up the shape. For now, this is what I'm using but I'd like to display my own shapes (rather than an ellipse or the stock shapes).

How would you get the series shape to show up for these custom polygons?

Thanks,

Matt

Parents
  • 30692
    Suggested Answer
    Offline posted

    Matt,

    For a series legend item, there is a Series in context, but not an item, because the Legend item is representing all the items in the series. So you can bind to properties on the series, but not on an item. So if you are having the items individually define a shape, that won't be accessible from the legend item badge. Are the points the same for every item in the series? Or do they differ? You could store them in an attached property on the Series and then bind at them on the series. Or you could specify a fallback shape as the fallback value of your binding so that something will get displayed if there is no item in the context.

    Also, if you want to manually override the template that a series will use as its legend item badge, you can set one on the LegendItemBadgeTemplate property for the series. For a scatter series, this defaults to trying to use the Marker template. But if your marker template cannot operate without an Item in context. You could specify a static badge to use for the series instead.

    Does this explaination help?

    -Graham

Reply Children