将椭圆添加到LiveCharts图

时间:2019-12-29 11:11:42

标签: c# livecharts

我正在尝试将ellipse添加到笛卡尔LiveCharts图中,以使其缩放和平移图上绘制的数据。我可以使用AddToView轻松地将一个添加到画布上(请参见下面的代码),但是在缩放或平移时它保持不变。我曾尝试在源代码中进行挖掘,但无法弄清楚如何在图形坐标中添加一个。

我知道我可以在图形上画出一个圆点,但是我要编写的应用程序将使用很多椭圆(会被放大),所以我不希望性能受到损害。

有人知道该怎么做吗?

XAML

<Window x:Class="EllipseExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:EllipseExample"
        xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <lvc:CartesianChart x:Name="myChart" Zoom="Xy"/>
</Window>

CS

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DrawGraphs();
            DrawEllipse();
        }
        public void DrawGraphs()
        {
            LineSeries mySeries = new LineSeries
            {
                Values = new ChartValues<ObservablePoint>
                        {
                            new ObservablePoint(1, 1),
                            new ObservablePoint(2, 1),
                            new ObservablePoint(3.5, 2),
                            new ObservablePoint(3, 2.2),
                        },
            };

            myChart.Series.Add(mySeries);
        }

        public void DrawEllipse()
        {
            Ellipse myEllipse = new Ellipse();
            myEllipse.Stroke = Brushes.Black;
            myEllipse.Width = 50;
            myEllipse.Height = 75;
            myChart.AddToView(myEllipse);
        }

    }

Graph window

0 个答案:

没有答案