Skip to content

Commit 8f56045

Browse files
Merge pull request #1 from SyncfusionExamples/TASK-860662_ScatterSample
TASK-860662_Added the sample for Scatter Chart
2 parents e1e3b02 + 99b77db commit 8f56045

File tree

12 files changed

+498
-2
lines changed

12 files changed

+498
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34309.116
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultipleSelection_ScatterPoints", "MultipleSelection_ScatterPoints\MultipleSelection_ScatterPoints.csproj", "{88D903F4-1846-4A23-8753-37D5A52EEAF1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B964A67A-259F-4C6F-B1F0-662B646556A6}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="MultipleSelection_ScatterPoints.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:MultipleSelection_ScatterPoints"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace MultipleSelection_ScatterPoints
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Syncfusion.UI.Xaml.Charts;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
using System.Windows.Media;
9+
10+
namespace MultipleSelection_ScatterPoints
11+
{
12+
public class ScatterAngleConverter : IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
15+
{
16+
var Value = value as ScatterSegment;
17+
if (Value != null)
18+
{
19+
var ydata = Value.YData;
20+
var angle = (ydata >= 25) ? 180 :0;
21+
22+
return angle;
23+
}
24+
25+
return 0;
26+
}
27+
28+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
29+
{
30+
throw new NotImplementedException();
31+
}
32+
}
33+
34+
public class ScatterAdornmentConverter : IValueConverter
35+
{
36+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
37+
{
38+
var Value = value as ChartAdornment;
39+
if (Value != null)
40+
{
41+
var ydata = Value.YData;
42+
var variate = (Value.Item as StockModel).Variation;
43+
if (ydata >= 25)
44+
return String.Format("+" + variate);
45+
return String.Format("-" + variate);
46+
}
47+
48+
return 0;
49+
}
50+
51+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
52+
{
53+
throw new NotImplementedException();
54+
}
55+
}
56+
57+
public class ScatterInteriorConverter : IValueConverter
58+
{
59+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
60+
{
61+
var Value = value as ScatterSegment;
62+
if (Value != null)
63+
{
64+
var ydata = Value.YData;
65+
Brush interior;
66+
67+
interior = ydata >= 25 ? new SolidColorBrush(Color.FromArgb(0xFF, 0x2B, 0xD2, 0x6E)) :
68+
new SolidColorBrush(Color.FromArgb(0xFF, 0xE3, 0x46, 0x5D)); ;
69+
70+
return interior;
71+
}
72+
73+
return value;
74+
}
75+
76+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
77+
{
78+
throw new NotImplementedException();
79+
}
80+
}
81+
82+
public class SymbolConverter : IValueConverter
83+
{
84+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
85+
{
86+
var Value = value as StockModel;
87+
if (Value != null)
88+
{
89+
var ydata = Value.Count;
90+
var variation = Value.Variation;
91+
92+
if (ydata >= 25)
93+
return String.Format("+" + variation);
94+
95+
return String.Format("-" + variation);
96+
}
97+
98+
return "N/A";
99+
}
100+
101+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
102+
{
103+
throw new NotImplementedException();
104+
}
105+
}
106+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<Window x:Class="MultipleSelection_ScatterPoints.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:MultipleSelection_ScatterPoints"
7+
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
8+
mc:Ignorable="d">
9+
10+
<Border Margin="20" Padding="4" BorderThickness="2" CornerRadius="10" BorderBrush="#b0b8bf">
11+
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="8*"/>
15+
<ColumnDefinition Width="1.7*"/>
16+
</Grid.ColumnDefinitions>
17+
18+
<Grid.DataContext>
19+
<local:StockData x:Name="viewModel"/>
20+
</Grid.DataContext>
21+
22+
<Grid.Resources>
23+
<local:ScatterAngleConverter x:Key="ScatterAngleConverter"/>
24+
<local:ScatterAdornmentConverter x:Key="ScatterAdornmentConverter"/>
25+
<local:SymbolConverter x:Key="SymbolConverter"/>
26+
<local:ScatterInteriorConverter x:Key="ScatterInteriorConverter"/>
27+
28+
<DataTemplate x:Key="seriesTemplate">
29+
<Canvas>
30+
<Path Canvas.Left="{Binding RectX}" Canvas.Top="{Binding RectY}" Width="{Binding ScatterWidth}"
31+
Height="{Binding ScatterHeight}" Data="M20.125,32L0.5,12.375L10.3125,12.375L10.3125,0.5L29.9375,0.5L29.9375,12.375L39.75,12.375z"
32+
Fill="{Binding Converter={StaticResource ScatterInteriorConverter}}" RenderTransformOrigin="0.5,0.5" Stretch="Fill">
33+
<Path.RenderTransform>
34+
<RotateTransform Angle="{Binding Converter={StaticResource ScatterAngleConverter}}"/>
35+
</Path.RenderTransform>
36+
</Path>
37+
</Canvas>
38+
</DataTemplate>
39+
40+
<DataTemplate x:Key="adornmentTemplate">
41+
<TextBlock FontSize="12" Foreground="White" Text="{Binding Converter={StaticResource ScatterAdornmentConverter}}"/>
42+
</DataTemplate>
43+
44+
<DataTemplate x:Key="headerTemplate2">
45+
<TextBlock Text="Stock Price" Padding="0,3,0,8" FontSize="14.5"/>
46+
</DataTemplate>
47+
48+
<DataTemplate x:Key="headerTemplate1">
49+
<TextBlock Text="Months" Padding="0,2,0,8" FontSize="14.5"/>
50+
</DataTemplate>
51+
</Grid.Resources>
52+
53+
<chart:SfChart Grid.Column="0">
54+
<chart:SfChart.Header>
55+
<TextBlock TextAlignment="Center" Text="Global Stock Trend" FontSize="17" Margin="0,10,0,10"/>
56+
</chart:SfChart.Header>
57+
58+
<chart:SfChart.PrimaryAxis>
59+
<chart:DateTimeAxis Interval="1" IntervalType="Months" LabelFormat="MMM" PlotOffset="30"
60+
HeaderTemplate="{StaticResource headerTemplate1}" ShowGridLines="False">
61+
<chart:DateTimeAxis.LabelStyle>
62+
<chart:LabelStyle FontSize="13"/>
63+
</chart:DateTimeAxis.LabelStyle>
64+
</chart:DateTimeAxis>
65+
</chart:SfChart.PrimaryAxis>
66+
67+
<chart:SfChart.SecondaryAxis>
68+
<chart:NumericalAxis Interval="10" Minimum="10" LabelFormat="$0" Maximum="80"
69+
HeaderTemplate="{StaticResource headerTemplate2}">
70+
<chart:NumericalAxis.LabelStyle>
71+
<chart:LabelStyle FontSize="12.5"/>
72+
</chart:NumericalAxis.LabelStyle>
73+
</chart:NumericalAxis>
74+
</chart:SfChart.SecondaryAxis>
75+
76+
<chart:ScatterSeries x:Name="series" ItemsSource="{Binding Data}" XBindingPath="Year" YBindingPath="Count"
77+
ScatterHeight="50" ScatterWidth="50" CustomTemplate="{StaticResource seriesTemplate}">
78+
<chart:ScatterSeries.AdornmentsInfo>
79+
<chart:ChartAdornmentInfo ShowLabel="True" SegmentLabelContent="LabelContentPath"
80+
LabelTemplate="{StaticResource adornmentTemplate}"/>
81+
</chart:ScatterSeries.AdornmentsInfo>
82+
</chart:ScatterSeries>
83+
84+
</chart:SfChart>
85+
86+
<Canvas Name="drawingCanvas" Background="Transparent" Grid.Column="0"
87+
MouseDown="OnMouseDown" MouseUp="OnMouseUp" Mouse.MouseMove="OnMouseMove"/>
88+
89+
<ListView Grid.Column="1" x:Name="listView" ItemsSource="{Binding SelectedDataPoints}" FontSize="16">
90+
<ListView.View>
91+
<GridView>
92+
<GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year, StringFormat=d}"/>
93+
<GridViewColumn Header="Count" DisplayMemberBinding="{Binding Count}"/>
94+
<GridViewColumn Header="Variation" DisplayMemberBinding="{Binding Converter={StaticResource SymbolConverter}}"/>
95+
</GridView>
96+
</ListView.View>
97+
</ListView>
98+
</Grid>
99+
</Border>
100+
</Window>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Syncfusion.UI.Xaml.Charts;
2+
using System.Collections.ObjectModel;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Shapes;
13+
14+
namespace MultipleSelection_ScatterPoints
15+
{
16+
/// <summary>
17+
/// Interaction logic for MainWindow.xaml
18+
/// </summary>
19+
public partial class MainWindow : Window
20+
{
21+
#region Fields
22+
23+
private Point startPoint;
24+
private Rectangle? currentRectangle;
25+
private Rect currentRect;
26+
27+
#endregion
28+
29+
#region Constructor
30+
31+
public MainWindow()
32+
{
33+
InitializeComponent();
34+
}
35+
36+
#endregion
37+
38+
#region Methods
39+
40+
private void OnMouseMove(object sender, MouseEventArgs e)
41+
{
42+
if (e.LeftButton == MouseButtonState.Pressed && currentRectangle != null)
43+
{
44+
// Update the size of the rectangle as the mouse is dragged
45+
double width = e.GetPosition(drawingCanvas).X - startPoint.X;
46+
double height = e.GetPosition(drawingCanvas).Y - startPoint.Y;
47+
if (width > 0 && height > 0)
48+
{
49+
currentRect = new Rect(startPoint.X, startPoint.Y, width, height);
50+
currentRectangle.Width = width;
51+
currentRectangle.Height = height;
52+
}
53+
}
54+
}
55+
56+
private void OnMouseDown(object sender, MouseButtonEventArgs e)
57+
{
58+
startPoint = e.GetPosition(drawingCanvas);
59+
60+
// Create a new rectangle
61+
currentRectangle = new Rectangle
62+
{
63+
Stroke = Brushes.Black,
64+
StrokeThickness = 1,
65+
Fill = Brushes.Transparent
66+
};
67+
68+
// Add the rectangle to the canvas
69+
drawingCanvas.Children.Add(currentRectangle);
70+
71+
// Set the initial position of the rectangle
72+
Canvas.SetLeft(currentRectangle, startPoint.X);
73+
Canvas.SetTop(currentRectangle, startPoint.Y);
74+
}
75+
76+
private void OnMouseUp(object sender, MouseButtonEventArgs e)
77+
{
78+
viewModel.SelectedDataPoints = series.GetDataPoints(currentRect);
79+
currentRectangle = null;
80+
currentRect = Rect.Empty;
81+
drawingCanvas.Children.Clear();
82+
}
83+
84+
#endregion
85+
}
86+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MultipleSelection_ScatterPoints
8+
{
9+
public class StockModel
10+
{
11+
public DateTime Year { get; set; }
12+
13+
public double Count { get; set; }
14+
15+
public double Variation { get; set; }
16+
17+
public StockModel(DateTime year, double count, double variation)
18+
{
19+
Year = year;
20+
Count = count;
21+
Variation = variation;
22+
}
23+
}
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.SfChart.WPF" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)