ChartView GC

0 Answers 36 Views
Chart
力源
Top achievements
Rank 1
力源 asked on 08 May 2024, 12:10 PM

ChartView experiences frequent garbage collection in TrackInfoUpdated after Tooltip of any control is activated.

    <Grid Loaded="Grid_Loaded">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel>
            <TextBlock x:Name="DTextBlock"></TextBlock>
            <StackPanel Width="200" Height="25" ToolTip="SSSS" Background="Red"></StackPanel>
        </StackPanel>
        <telerik:RadCartesianChart Grid.Row="1" x:Name="DMainChart">
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:DateTimeCategoricalAxis MajorTickInterval="30" LineStroke="Transparent">
                </telerik:DateTimeCategoricalAxis>
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis />
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:RadCartesianChart.Series>
                <telerik:LineSeries x:Name="DLineSeries" CategoryBinding="Seq" ValueBinding="Open"></telerik:LineSeries>
            </telerik:RadCartesianChart.Series>
            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartPanAndZoomBehavior ZoomMode="Horizontal" DragMode="Pan"/>
                <telerik:ChartTrackBallBehavior ShowIntersectionPoints="False" ShowTrackInfo="False" TrackInfoUpdated="ChartTrackBallBehavior_TrackInfoUpdated"/>
            </telerik:RadCartesianChart.Behaviors>
        </telerik:RadCartesianChart>
    </Grid>

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            if (sender is Grid grid)
            {
                grid.DataContext = this;
                ObservableCollection<SeriesKLineModel> ChartKLine = new ObservableCollection<SeriesKLineModel>();
                Random random = new Random();
                for (int i = 0; i < 5000; i++)
                {
                    SeriesKLineModel mode = new SeriesKLineModel(DateTime.Now.AddDays(i), random.Next(10, 20), 5, -5, 0, Color.FromRgb(33, 141, 252));
                    mode.Seq = mode.Seq.AddHours((-1) * i);
                    ChartKLine.Add(mode);
                }
                this.DLineSeries.ItemsSource = ChartKLine;
                this.DTextBlock.SetBinding(TextBlock.TextProperty, new Binding(nameof(TestText)));
            }
        }
        private string _TestText = "";
        public event PropertyChangedEventHandler PropertyChanged;
        public string TestText
        {
            get
            {
                return _TestText;
            }
            set
            {
                _TestText = value;
                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TestText)));
            }
        }

        private void ChartTrackBallBehavior_TrackInfoUpdated(object sender, Telerik.Windows.Controls.ChartView.TrackBallInfoEventArgs e)
        {
            DataPointInfo pointInfo = e.Context?.ClosestDataPoint;
            if (pointInfo != null && pointInfo.DataPoint.DataItem is SeriesKLineModel data)
            {
                string str = data.Seq.ToLongDateString();
                Task.Run(() =>
                {
                    this.TestText = str;
                });
            }
        }

No answers yet. Maybe you can help?

Tags
Chart
Asked by
力源
Top achievements
Rank 1
Share this question
or