Home > Mobile >  C# WPF Live Charts rendering a point as an image
C# WPF Live Charts rendering a point as an image

Time:04-03

Is there a way for rendering a point in a scatter plot as an image in Live Charts for WPF? I can change the shape of it with PointGeometry. There are some DefaultGeometries as Circle, Triangle etc. But what about an image? For example logo of a sports team in plotting some sport stats.

CodePudding user response:

I have found a solution:

In view model:

private VisualElementsCollection visuals = new VisualElementsCollection();
        public VisualElementsCollection Visuals
        {
            get { return visuals; }
            set
            {
                visuals = value;
                OnPropertyChanged();
            }
        }
Visuals.Add(new VisualElement
                    {
                        X = 1.5,
                        Y = 2.8,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment = VerticalAlignment.Center,

                        UIElement = new Image
                        {
                            Source = logo,
                            MaxWidth = 50,
                            MaxHeight = 50
                        }
                    });

In view:

<lvc:CartesianChart LegendLocation="Bottom" Series="{Binding ScatterSeries}"  VisualElements="{Binding Visuals}" Hoverable="False" Width="750" Height="750">
  • Related