How to resolve overlapping charts (C# WPF Oxyplot)

69 Views Asked by At

There are two tabs in my wpf program.(Main, History) In the main tap, two charts are drawing data in real time. When start a program, show the main tap, and when you show historical data, you go to the History tab. This is where the problem occurs. When you return to the main tab from the history tab, the chart in the main tab disappears or the x and y axes overlap. I will upload the xaml and c codes of history tab and main tab. What's the problem?

MainChart.View

<Page.DataContext>
        <vm:iOChartVM/>
    </Page.DataContext>

    <Grid>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <command:EventToCommand Command="{Binding WindowsLoaded}" PassEventArgsToCommand="True"></command:EventToCommand>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        
        <oxy:PlotView BorderBrush="Black" />
    </Grid>

iOChartVM.cs

private ICommand _WindowsLoaded;
        public ICommand WindowsLoaded => _WindowsLoaded ?? (_WindowsLoaded = new RelayCommand<RoutedEventArgs>((e) =>
        {
            try
            {
                Panel panel = e.Source as Panel;
                //PlotView = new PlotView();
                DataGrid tempDatagrid = new DataGrid();

                for (int iChildren = 0; iChildren < panel.Children.Count; iChildren++)
                {
                    if (panel.Children[iChildren] is PlotView)
                    {
                        PlotView = panel.Children[iChildren] as PlotView;
                        PlotView.Model = new PlotModel();
                    }
                }

                ChartDrawTimerAI.Tick += Timer_Tick;

                TrendGraphAI.SetPlotView(PlotView);
                TrendGraphAI.SettupConfig(0, "test");
                TrendGraphAI.AddyAis(0, "mA", OxyPlot.Axes.AxisPosition.Left, 0, "L1", 3, 21, true, "Analog");

HistoryChart.View

<Page.DataContext>
        <vm:AIHistoryVM/>
    </Page.DataContext>

    <Grid>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <command:EventToCommand Command="{Binding WindowsLoaded}" PassEventArgsToCommand="True"></command:EventToCommand>
            </i:EventTrigger>
        </i:Interaction.Triggers>

        <oxy:PlotView BorderBrush="Cyan" />
    </Grid>

AIHistoryVM.cs

private ICommand _WindowsLoaded;
        public ICommand WindowsLoaded => _WindowsLoaded ?? (_WindowsLoaded = new RelayCommand<RoutedEventArgs>((e) =>
        {
            try
            {
                Panel panel = e.Source as Panel;
                PlotView = new PlotView();
                DataGrid tempDatagrid = new DataGrid();

                for (int iChildren = 0; iChildren < panel.Children.Count; iChildren++)
                {
                    if (panel.Children[iChildren] is PlotView)
                    {
                        PlotView = panel.Children[iChildren] as PlotView;
                        PlotView.Model = new PlotModel();
                    }
                }

                TrendGraph.SetPlotView(PlotView);

                TrendGraph.SettupConfig(0, "test");
0

There are 0 best solutions below