-
Notifications
You must be signed in to change notification settings - Fork 0
Updated the trackball sample #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Saravanan-Madhesh
merged 10 commits into
master
from
Prepare_sample_for_trackball_synchronize
Jan 2, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
727e8e9
Updated the trackball sample
37e7e07
deleted the user proj file
9ee89de
Removed the json and updated the label format
b009a13
removed .vs file
5d253ac
Update README.md
4570180
Update README.md
1638ece
Update README.md
a24a745
Update README.md
VimalaThirumalaikumar 19881a1
created the model and view model in seperate class
1cd0517
Merge branch 'Prepare_sample_for_trackball_synchronize' of https://gi…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,19 @@ | ||
| # 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. | ||
|
|
||
| # Output | ||
|  | ||
|
|
||
|
|
||
| # 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Application x:Class="Synchronize_Trackball.App" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:local="clr-namespace:Synchronize_Trackball" | ||
| StartupUri="MainWindow.xaml"> | ||
| <Application.Resources> | ||
|
|
||
| </Application.Resources> | ||
| </Application> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Configuration; | ||
| using System.Data; | ||
| using System.Windows; | ||
|
|
||
| namespace Synchronize_Trackball | ||
| { | ||
| /// <summary> | ||
| /// Interaction logic for App.xaml | ||
| /// </summary> | ||
| public partial class App : Application | ||
| { | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| )] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <Window x:Class="Synchronize_Trackball.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:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF" | ||
| xmlns:local="clr-namespace:Synchronize_Trackball" | ||
| mc:Ignorable="d" | ||
| Title="MainWindow" Height="450" Width="800"> | ||
| <Grid> | ||
| <Grid.DataContext> | ||
| <local:DataGenerator/> | ||
| </Grid.DataContext> | ||
|
|
||
| <Grid.RowDefinitions> | ||
| <RowDefinition /> | ||
| <RowDefinition /> | ||
| </Grid.RowDefinitions> | ||
|
|
||
| <chart:SfChart x:Name="chart1" MouseMove="SfChart_MouseMove1" Header="FirstChart" Margin="5"> | ||
|
|
||
| <chart:SfChart.Behaviors> | ||
| <local:CustomTrackBallBehavior x:Name="behavior1"/> | ||
| </chart:SfChart.Behaviors> | ||
|
|
||
| <chart:SfChart.PrimaryAxis> | ||
| <chart:DateTimeAxis ShowTrackBallInfo="True" x:Name="axis" LabelFormat="MMM-dd" /> | ||
| </chart:SfChart.PrimaryAxis> | ||
|
|
||
| <chart:SfChart.SecondaryAxis> | ||
| <chart:NumericalAxis ShowTrackBallInfo="True" x:Name="secAxis"/> | ||
| </chart:SfChart.SecondaryAxis> | ||
|
|
||
| <chart:FastLineSeries x:Name="series1" XBindingPath="Date" YBindingPath="Value" | ||
| ItemsSource="{Binding DataCollection1}"/> | ||
|
|
||
| </chart:SfChart> | ||
|
|
||
| <chart:SfChart x:Name="chart2" MouseMove="SfChart_MouseMove2" Grid.Row="1" Grid.Column="0" Header="Second Chart" Margin="5"> | ||
|
|
||
| <chart:SfChart.Behaviors> | ||
| <local:CustomTrackBallBehavior x:Name="behavior2"/> | ||
| </chart:SfChart.Behaviors> | ||
|
|
||
| <chart:SfChart.PrimaryAxis> | ||
| <chart:DateTimeAxis ShowTrackBallInfo="True" LabelFormat="MMM-dd"/> | ||
| </chart:SfChart.PrimaryAxis> | ||
|
|
||
| <chart:SfChart.SecondaryAxis> | ||
| <chart:NumericalAxis ShowTrackBallInfo="True" /> | ||
| </chart:SfChart.SecondaryAxis> | ||
|
|
||
| <chart:FastLineSeries x:Name="series3" XBindingPath="Date" YBindingPath="Value" | ||
| ItemsSource="{Binding DataCollection2}"/> | ||
| </chart:SfChart> | ||
| </Grid> | ||
| </Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| 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 | ||
| { | ||
| /// <summary> | ||
| /// Interaction logic for MainWindow.xaml | ||
| /// </summary> | ||
| 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 | ||
VimalaThirumalaikumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public void ActivateTrackball(Point mousePoint) | ||
| { | ||
| IsActivated = true; | ||
| OnPointerPositionChanged(mousePoint); | ||
| } | ||
|
|
||
| public void DeactivateTrackball() | ||
| { | ||
| IsActivated = false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>WinExe</OutputType> | ||
| <TargetFramework>net8.0-windows</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <UseWPF>true</UseWPF> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Syncfusion.SfChart.WPF" Version="*" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Data> DataCollection1 { get; set; } | ||
| public ObservableCollection<Data> DataCollection2 { get; set; } | ||
|
|
||
| public DataGenerator() | ||
| { | ||
| randomNumber = new Random(); | ||
| DataCollection1 = GenerateData(); | ||
| DataCollection2 = GenerateData(); | ||
| } | ||
|
|
||
| public ObservableCollection<Data> GenerateData() | ||
| { | ||
| ObservableCollection<Data> datas = new ObservableCollection<Data>(); | ||
| 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; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.