From 727e8e97143e04c1a193f7f2b472af432682d58b Mon Sep 17 00:00:00 2001 From: NitheeshKumarThangaraj Date: Wed, 18 Dec 2024 12:32:42 +0530 Subject: [PATCH 1/9] Updated the trackball sample --- .../v17/DocumentLayout.json | 65 +++++++ Synchronize_Trackball/App.xaml | 9 + Synchronize_Trackball/App.xaml.cs | 14 ++ Synchronize_Trackball/AssemblyInfo.cs | 10 ++ Synchronize_Trackball/MainWindow.xaml | 57 +++++++ Synchronize_Trackball/MainWindow.xaml.cs | 158 ++++++++++++++++++ .../Synchronize_Trackball.csproj | 15 ++ .../Synchronize_Trackball.csproj.user | 14 ++ .../Synchronize_Trackball.sln | 22 +++ 9 files changed, 364 insertions(+) create mode 100644 Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json create mode 100644 Synchronize_Trackball/App.xaml create mode 100644 Synchronize_Trackball/App.xaml.cs create mode 100644 Synchronize_Trackball/AssemblyInfo.cs create mode 100644 Synchronize_Trackball/MainWindow.xaml create mode 100644 Synchronize_Trackball/MainWindow.xaml.cs create mode 100644 Synchronize_Trackball/Synchronize_Trackball.csproj create mode 100644 Synchronize_Trackball/Synchronize_Trackball.csproj.user create mode 100644 Synchronize_Trackball/Synchronize_Trackball.sln diff --git a/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json b/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json new file mode 100644 index 0000000..a1d5dc4 --- /dev/null +++ b/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json @@ -0,0 +1,65 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\WPF Samples\\Synchronize_Trackball\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|d:\\wpf samples\\synchronize_trackball\\mainwindow.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}", + "RelativeMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|solutionrelative:mainwindow.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}" + }, + { + "AbsoluteMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|d:\\wpf samples\\synchronize_trackball\\mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|solutionrelative:mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 4, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{d78612c7-9962-4b83-95d9-268046dad23a}" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "MainWindow.xaml.cs", + "DocumentMoniker": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml.cs", + "RelativeDocumentMoniker": "MainWindow.xaml.cs", + "ToolTip": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml.cs", + "RelativeToolTip": "MainWindow.xaml.cs", + "ViewState": "AgIAAEcAAAAAAAAAAAAuwGAAAAAFAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-12-13T10:58:11.468Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "MainWindow.xaml", + "DocumentMoniker": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml", + "RelativeDocumentMoniker": "MainWindow.xaml", + "ToolTip": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml", + "RelativeToolTip": "MainWindow.xaml", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|", + "WhenOpened": "2024-12-13T10:58:05.535Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Synchronize_Trackball/App.xaml b/Synchronize_Trackball/App.xaml new file mode 100644 index 0000000..ad081dd --- /dev/null +++ b/Synchronize_Trackball/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Synchronize_Trackball/App.xaml.cs b/Synchronize_Trackball/App.xaml.cs new file mode 100644 index 0000000..f5fd4ae --- /dev/null +++ b/Synchronize_Trackball/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace Synchronize_Trackball +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/Synchronize_Trackball/AssemblyInfo.cs b/Synchronize_Trackball/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/Synchronize_Trackball/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Synchronize_Trackball/MainWindow.xaml b/Synchronize_Trackball/MainWindow.xaml new file mode 100644 index 0000000..fd6cffb --- /dev/null +++ b/Synchronize_Trackball/MainWindow.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Synchronize_Trackball/MainWindow.xaml.cs b/Synchronize_Trackball/MainWindow.xaml.cs new file mode 100644 index 0000000..bf42230 --- /dev/null +++ b/Synchronize_Trackball/MainWindow.xaml.cs @@ -0,0 +1,158 @@ +using System.Collections.ObjectModel; +using Syncfusion.UI.Xaml.Charts; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Synchronize_Trackball +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public Point MousePoint + { + get; + set; + } + + public MainWindow() + { + InitializeComponent(); + } + + private void SfChart_MouseMove1(object sender, MouseEventArgs e) + { + // Taking the first chart position as reference to get the mouse point. + MousePoint = Mouse.GetPosition(behavior1.AdorningCanvas); + var chart1 = (sender as SfChart); + + if (chart1.SeriesClipRect.Contains(MousePoint)) + { + // Generalizing position with respect to axis width. + MousePoint = new Point( + MousePoint.X - chart1.SeriesClipRect.Left, + MousePoint.Y - chart1.SeriesClipRect.Top); + + behavior1.ActivateTrackball(MousePoint); + behavior2.ActivateTrackball(MousePoint); + } + else + { + behavior1.DeactivateTrackball(); + behavior2.DeactivateTrackball(); + } + } + + private void SfChart_MouseMove2(object sender, MouseEventArgs e) + { + // Taking the second chart position as reference to get the mouse point. + MousePoint = Mouse.GetPosition(behavior2.AdorningCanvas); + var chart2 = (sender as SfChart); + + if (chart2.SeriesClipRect.Contains(MousePoint)) + { + // Generalizing position with respect to axis width. + MousePoint = new Point( + MousePoint.X - chart2.SeriesClipRect.Left, + MousePoint.Y - chart2.SeriesClipRect.Top); + + behavior1.ActivateTrackball(MousePoint); + behavior2.ActivateTrackball(MousePoint); + } + else + { + behavior1.DeactivateTrackball(); + behavior2.DeactivateTrackball(); + } + } + } + + + public class CustomTrackBallBehavior : ChartTrackBallBehavior + { + public void ActivateTrackball(Point mousePoint) + { + IsActivated = true; + OnPointerPositionChanged(mousePoint); + } + + public void DeactivateTrackball() + { + IsActivated = false; + } + + // This method is overriden to improve perfomance by preventing the mouse position calculation which we have done already. + protected override void OnMouseMove(MouseEventArgs e) + { + } + } + + public class Data + { + public Data(DateTime date, double value) + { + Date = date; + Value = value; + } + + public DateTime Date + { + get; + set; + } + + public double Value + { + get; + set; + } + } + + public class DataGenerator + { + public int DataCount = 100; + private Random randomNumber; + public ObservableCollection DataCollection1 { get; set; } + public ObservableCollection DataCollection2 { get; set; } + + public DataGenerator() + { + randomNumber = new Random(); + DataCollection1 = GenerateData(); + DataCollection2 = GenerateData(); + } + + public ObservableCollection GenerateData() + { + ObservableCollection datas = new ObservableCollection(); + DateTime date = new DateTime(2020, 1, 1); + double value = 100; + + for (int i = 0; i < this.DataCount; i++) + { + datas.Add(new Data(date, Math.Round(value, 2))); + date = date.Add(TimeSpan.FromDays(1)); + + if (randomNumber.NextDouble() > .5) + { + value += randomNumber.NextDouble(); + } + else + { + value -= randomNumber.NextDouble(); + } + } + + return datas; + } + } +} \ No newline at end of file diff --git a/Synchronize_Trackball/Synchronize_Trackball.csproj b/Synchronize_Trackball/Synchronize_Trackball.csproj new file mode 100644 index 0000000..52478d0 --- /dev/null +++ b/Synchronize_Trackball/Synchronize_Trackball.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + diff --git a/Synchronize_Trackball/Synchronize_Trackball.csproj.user b/Synchronize_Trackball/Synchronize_Trackball.csproj.user new file mode 100644 index 0000000..644b0a6 --- /dev/null +++ b/Synchronize_Trackball/Synchronize_Trackball.csproj.user @@ -0,0 +1,14 @@ + + + + + + Designer + + + + + Designer + + + \ No newline at end of file diff --git a/Synchronize_Trackball/Synchronize_Trackball.sln b/Synchronize_Trackball/Synchronize_Trackball.sln new file mode 100644 index 0000000..8fc685c --- /dev/null +++ b/Synchronize_Trackball/Synchronize_Trackball.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35506.116 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Synchronize_Trackball", "Synchronize_Trackball.csproj", "{2AE8056D-FC80-4398-A603-35E59086C4CA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2AE8056D-FC80-4398-A603-35E59086C4CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2AE8056D-FC80-4398-A603-35E59086C4CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AE8056D-FC80-4398-A603-35E59086C4CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2AE8056D-FC80-4398-A603-35E59086C4CA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 37e7e0713fa65ef60ced551fe57cd5fadc27077f Mon Sep 17 00:00:00 2001 From: NitheeshKumarThangaraj Date: Tue, 31 Dec 2024 16:30:48 +0530 Subject: [PATCH 2/9] deleted the user proj file --- .../Synchronize_Trackball.csproj.user | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Synchronize_Trackball/Synchronize_Trackball.csproj.user diff --git a/Synchronize_Trackball/Synchronize_Trackball.csproj.user b/Synchronize_Trackball/Synchronize_Trackball.csproj.user deleted file mode 100644 index 644b0a6..0000000 --- a/Synchronize_Trackball/Synchronize_Trackball.csproj.user +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - Designer - - - - - Designer - - - \ No newline at end of file From 9ee89dee7c0e8a9c895d0189fe1f9be514801cc3 Mon Sep 17 00:00:00 2001 From: NitheeshKumarThangaraj Date: Tue, 31 Dec 2024 17:36:08 +0530 Subject: [PATCH 3/9] Removed the json and updated the label format --- Synchronize_Trackball/MainWindow.xaml | 4 ++-- Synchronize_Trackball/MainWindow.xaml.cs | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Synchronize_Trackball/MainWindow.xaml b/Synchronize_Trackball/MainWindow.xaml index fd6cffb..e0057c0 100644 --- a/Synchronize_Trackball/MainWindow.xaml +++ b/Synchronize_Trackball/MainWindow.xaml @@ -24,7 +24,7 @@ - + @@ -43,7 +43,7 @@ - + diff --git a/Synchronize_Trackball/MainWindow.xaml.cs b/Synchronize_Trackball/MainWindow.xaml.cs index bf42230..d3f2e9f 100644 --- a/Synchronize_Trackball/MainWindow.xaml.cs +++ b/Synchronize_Trackball/MainWindow.xaml.cs @@ -89,11 +89,6 @@ public void DeactivateTrackball() { IsActivated = false; } - - // This method is overriden to improve perfomance by preventing the mouse position calculation which we have done already. - protected override void OnMouseMove(MouseEventArgs e) - { - } } public class Data From b009a13ae0b9d8039b4f06386c980e240677c02d Mon Sep 17 00:00:00 2001 From: NitheeshKumarThangaraj Date: Tue, 31 Dec 2024 17:43:26 +0530 Subject: [PATCH 4/9] removed .vs file --- .../v17/DocumentLayout.json | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json diff --git a/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json b/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json deleted file mode 100644 index a1d5dc4..0000000 --- a/Synchronize_Trackball/.vs/Synchronize_Trackball/v17/DocumentLayout.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "Version": 1, - "WorkspaceRootPath": "D:\\WPF Samples\\Synchronize_Trackball\\", - "Documents": [ - { - "AbsoluteMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|d:\\wpf samples\\synchronize_trackball\\mainwindow.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}", - "RelativeMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|solutionrelative:mainwindow.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}" - }, - { - "AbsoluteMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|d:\\wpf samples\\synchronize_trackball\\mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", - "RelativeMoniker": "D:0:0:{2AE8056D-FC80-4398-A603-35E59086C4CA}|Synchronize_Trackball.csproj|solutionrelative:mainwindow.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" - } - ], - "DocumentGroupContainers": [ - { - "Orientation": 0, - "VerticalTabListWidth": 256, - "DocumentGroups": [ - { - "DockedWidth": 200, - "SelectedChildIndex": 4, - "Children": [ - { - "$type": "Bookmark", - "Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}" - }, - { - "$type": "Bookmark", - "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}" - }, - { - "$type": "Bookmark", - "Name": "ST:0:0:{d78612c7-9962-4b83-95d9-268046dad23a}" - }, - { - "$type": "Document", - "DocumentIndex": 1, - "Title": "MainWindow.xaml.cs", - "DocumentMoniker": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml.cs", - "RelativeDocumentMoniker": "MainWindow.xaml.cs", - "ToolTip": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml.cs", - "RelativeToolTip": "MainWindow.xaml.cs", - "ViewState": "AgIAAEcAAAAAAAAAAAAuwGAAAAAFAAAAAAAAAA==", - "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-12-13T10:58:11.468Z", - "EditorCaption": "" - }, - { - "$type": "Document", - "DocumentIndex": 0, - "Title": "MainWindow.xaml", - "DocumentMoniker": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml", - "RelativeDocumentMoniker": "MainWindow.xaml", - "ToolTip": "D:\\WPF Samples\\Synchronize_Trackball\\MainWindow.xaml", - "RelativeToolTip": "MainWindow.xaml", - "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|", - "WhenOpened": "2024-12-13T10:58:05.535Z", - "EditorCaption": "" - } - ] - } - ] - } - ] -} \ No newline at end of file From 5d253ac453635ff7dc064cc4ec1b9bf5ce2e89b8 Mon Sep 17 00:00:00 2001 From: NitheeshkumarThangaraj <113961867+NitheeshkumarThangaraj@users.noreply.github.com> Date: Tue, 31 Dec 2024 18:27:50 +0530 Subject: [PATCH 5/9] Update README.md --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66a73f6..2b5466e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# How-to-synchronize-the-trackball-with-different-chart-area-in-WPF-Chart -This article shows how to synchronize the trackball with different chart area in WPF Chart +# How-to-synchronize-the-trackball-in-multiple-WPF-Charts +This article explains how to synchronize the Trackball in multiple WPF Charts using Syncfusion's SfChart control.Synchronizing the Trackball across multiple charts allows users to view related data points in different charts simultaneously, enhancing the data analysis experience. This is particularly useful when dealing with comparative data spread across multiple series or charts, as it provides a unified interaction mechanism. + +# SFChart + +The SfChart is a powerful and flexible charting library designed to render high-performance charts with a wide variety of customizable features. It supports multiple chart types, including Line, Bar, Area, and more, making it an excellent tool for visualizing complex datasets. + + # Trackball + +The TrackballBehavior is a useful feature in the SfChart that enables users to display interactive data tooltips when hovering over a chart. It provides detailed information about data points, such as their X and Y values, and can be customized to display additional content as required. + +# Troubleshooting +If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project. + +For a step by step procedure, refer to the [Synchronize trackball]() KB article. From 4570180e3cef65f7cc2d818c0471ef96e879ab07 Mon Sep 17 00:00:00 2001 From: NitheeshkumarThangaraj <113961867+NitheeshkumarThangaraj@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:53:54 +0530 Subject: [PATCH 6/9] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b5466e..cb99ea4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# How-to-synchronize-the-trackball-in-multiple-WPF-Charts +# How to synchronize the trackball in multiple WPF Charts This article explains how to synchronize the Trackball in multiple WPF Charts using Syncfusion's SfChart control.Synchronizing the Trackball across multiple charts allows users to view related data points in different charts simultaneously, enhancing the data analysis experience. This is particularly useful when dealing with comparative data spread across multiple series or charts, as it provides a unified interaction mechanism. # SFChart @@ -9,6 +9,10 @@ The SfChart is a powerful and flexible charting library designed to render high- The TrackballBehavior is a useful feature in the SfChart that enables users to display interactive data tooltips when hovering over a chart. It provides detailed information about data points, such as their X and Y values, and can be customized to display additional content as required. +# Output +![MainWindow 2025-01-02 12-19-29](https://github.com/user-attachments/assets/3e401e8c-b56c-4de5-a6ae-c13c20af52f9) + + # Troubleshooting If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project. From 1638ece9837b6496856954403d7d3c6c0eb53fb8 Mon Sep 17 00:00:00 2001 From: NitheeshkumarThangaraj <113961867+NitheeshkumarThangaraj@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:56:34 +0530 Subject: [PATCH 7/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb99ea4..424645f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The SfChart is a powerful and flexible charting library designed to render high- The TrackballBehavior is a useful feature in the SfChart that enables users to display interactive data tooltips when hovering over a chart. It provides detailed information about data points, such as their X and Y values, and can be customized to display additional content as required. # Output -![MainWindow 2025-01-02 12-19-29](https://github.com/user-attachments/assets/3e401e8c-b56c-4de5-a6ae-c13c20af52f9) +![Synchronize trackballs](https://github.com/user-attachments/assets/3e401e8c-b56c-4de5-a6ae-c13c20af52f9) # Troubleshooting From a24a74525c6d9ebe5f77d0514406f938b1ae59f3 Mon Sep 17 00:00:00 2001 From: VimalaThirumalaiKumarSF3739 <105496706+VimalaThirumalaiKumarSF3739@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:45:53 +0530 Subject: [PATCH 8/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 424645f..2c6d0e9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # How to synchronize the trackball in multiple WPF Charts -This article explains how to synchronize the Trackball in multiple WPF Charts using Syncfusion's SfChart control.Synchronizing the Trackball across multiple charts allows users to view related data points in different charts simultaneously, enhancing the data analysis experience. This is particularly useful when dealing with comparative data spread across multiple series or charts, as it provides a unified interaction mechanism. +This article explains how to synchronize the Trackball in multiple WPF Charts using Syncfusion's SfChart control. Synchronizing the Trackball across multiple charts allows users to view related data points in different charts simultaneously, enhancing the data analysis experience. This is particularly useful when dealing with comparative data spread across multiple series or charts, as it provides a unified interaction mechanism. # SFChart From 19881a1425657b33e7f6ff668c065cd5a3980030 Mon Sep 17 00:00:00 2001 From: NitheeshKumarThangaraj Date: Thu, 2 Jan 2025 16:58:39 +0530 Subject: [PATCH 9/9] created the model and view model in seperate class --- Synchronize_Trackball/MainWindow.xaml.cs | 61 ------------------- Synchronize_Trackball/Model/Data.cs | 29 +++++++++ .../ViewModel/DataGenerator.cs | 49 +++++++++++++++ 3 files changed, 78 insertions(+), 61 deletions(-) create mode 100644 Synchronize_Trackball/Model/Data.cs create mode 100644 Synchronize_Trackball/ViewModel/DataGenerator.cs diff --git a/Synchronize_Trackball/MainWindow.xaml.cs b/Synchronize_Trackball/MainWindow.xaml.cs index d3f2e9f..7883394 100644 --- a/Synchronize_Trackball/MainWindow.xaml.cs +++ b/Synchronize_Trackball/MainWindow.xaml.cs @@ -76,7 +76,6 @@ private void SfChart_MouseMove2(object sender, MouseEventArgs e) } } - public class CustomTrackBallBehavior : ChartTrackBallBehavior { public void ActivateTrackball(Point mousePoint) @@ -90,64 +89,4 @@ public void DeactivateTrackball() IsActivated = false; } } - - public class Data - { - public Data(DateTime date, double value) - { - Date = date; - Value = value; - } - - public DateTime Date - { - get; - set; - } - - public double Value - { - get; - set; - } - } - - public class DataGenerator - { - public int DataCount = 100; - private Random randomNumber; - public ObservableCollection DataCollection1 { get; set; } - public ObservableCollection DataCollection2 { get; set; } - - public DataGenerator() - { - randomNumber = new Random(); - DataCollection1 = GenerateData(); - DataCollection2 = GenerateData(); - } - - public ObservableCollection GenerateData() - { - ObservableCollection datas = new ObservableCollection(); - DateTime date = new DateTime(2020, 1, 1); - double value = 100; - - for (int i = 0; i < this.DataCount; i++) - { - datas.Add(new Data(date, Math.Round(value, 2))); - date = date.Add(TimeSpan.FromDays(1)); - - if (randomNumber.NextDouble() > .5) - { - value += randomNumber.NextDouble(); - } - else - { - value -= randomNumber.NextDouble(); - } - } - - return datas; - } - } } \ No newline at end of file diff --git a/Synchronize_Trackball/Model/Data.cs b/Synchronize_Trackball/Model/Data.cs new file mode 100644 index 0000000..9d6215e --- /dev/null +++ b/Synchronize_Trackball/Model/Data.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Synchronize_Trackball +{ + public class Data + { + public Data(DateTime date, double value) + { + Date = date; + Value = value; + } + + public DateTime Date + { + get; + set; + } + + public double Value + { + get; + set; + } + } +} diff --git a/Synchronize_Trackball/ViewModel/DataGenerator.cs b/Synchronize_Trackball/ViewModel/DataGenerator.cs new file mode 100644 index 0000000..db231a1 --- /dev/null +++ b/Synchronize_Trackball/ViewModel/DataGenerator.cs @@ -0,0 +1,49 @@ +using Synchronize_Trackball; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Synchronize_Trackball +{ + public class DataGenerator + { + public int DataCount = 100; + private Random randomNumber; + public ObservableCollection DataCollection1 { get; set; } + public ObservableCollection DataCollection2 { get; set; } + + public DataGenerator() + { + randomNumber = new Random(); + DataCollection1 = GenerateData(); + DataCollection2 = GenerateData(); + } + + public ObservableCollection GenerateData() + { + ObservableCollection datas = new ObservableCollection(); + DateTime date = new DateTime(2020, 1, 1); + double value = 100; + + for (int i = 0; i < DataCount; i++) + { + datas.Add(new Data(date, Math.Round(value, 2))); + date = date.Add(TimeSpan.FromDays(1)); + + if (randomNumber.NextDouble() > .5) + { + value += randomNumber.NextDouble(); + } + else + { + value -= randomNumber.NextDouble(); + } + } + + return datas; + } + } +}