Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultipleSelection_ScatterPoints", "MultipleSelection_ScatterPoints\MultipleSelection_ScatterPoints.csproj", "{88D903F4-1846-4A23-8753-37D5A52EEAF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88D903F4-1846-4A23-8753-37D5A52EEAF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B964A67A-259F-4C6F-B1F0-662B646556A6}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="MultipleSelection_ScatterPoints.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MultipleSelection_ScatterPoints"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace MultipleSelection_ScatterPoints
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
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)
)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Syncfusion.UI.Xaml.Charts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace MultipleSelection_ScatterPoints
{
public class ScatterAngleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var Value = value as ScatterSegment;
if (Value != null)
{
var ydata = Value.YData;
var angle = (ydata >= 25) ? 180 :0;

return angle;
}

return 0;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class ScatterAdornmentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var Value = value as ChartAdornment;
if (Value != null)
{
var ydata = Value.YData;
var variate = (Value.Item as StockModel).Variation;
if (ydata >= 25)
return String.Format("+" + variate);
return String.Format("-" + variate);
}

return 0;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class ScatterInteriorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var Value = value as ScatterSegment;
if (Value != null)
{
var ydata = Value.YData;
Brush interior;

interior = ydata >= 25 ? new SolidColorBrush(Color.FromArgb(0xFF, 0x2B, 0xD2, 0x6E)) :
new SolidColorBrush(Color.FromArgb(0xFF, 0xE3, 0x46, 0x5D)); ;

return interior;
}

return value;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class SymbolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var Value = value as StockModel;
if (Value != null)
{
var ydata = Value.Count;
var variation = Value.Variation;

if (ydata >= 25)
return String.Format("+" + variation);

return String.Format("-" + variation);
}

return "N/A";
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<Window x:Class="MultipleSelection_ScatterPoints.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:local="clr-namespace:MultipleSelection_ScatterPoints"
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
mc:Ignorable="d">

<Border Margin="20" Padding="4" BorderThickness="2" CornerRadius="10" BorderBrush="#b0b8bf">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="1.7*"/>
</Grid.ColumnDefinitions>

<Grid.DataContext>
<local:StockData x:Name="viewModel"/>
</Grid.DataContext>

<Grid.Resources>
<local:ScatterAngleConverter x:Key="ScatterAngleConverter"/>
<local:ScatterAdornmentConverter x:Key="ScatterAdornmentConverter"/>
<local:SymbolConverter x:Key="SymbolConverter"/>
<local:ScatterInteriorConverter x:Key="ScatterInteriorConverter"/>

<DataTemplate x:Key="seriesTemplate">
<Canvas>
<Path Canvas.Left="{Binding RectX}" Canvas.Top="{Binding RectY}" Width="{Binding ScatterWidth}"
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"
Fill="{Binding Converter={StaticResource ScatterInteriorConverter}}" RenderTransformOrigin="0.5,0.5" Stretch="Fill">
<Path.RenderTransform>
<RotateTransform Angle="{Binding Converter={StaticResource ScatterAngleConverter}}"/>
</Path.RenderTransform>
</Path>
</Canvas>
</DataTemplate>

<DataTemplate x:Key="adornmentTemplate">
<TextBlock FontSize="12" Foreground="White" Text="{Binding Converter={StaticResource ScatterAdornmentConverter}}"/>
</DataTemplate>

<DataTemplate x:Key="headerTemplate2">
<TextBlock Text="Stock Price" Padding="0,3,0,8" FontSize="14.5"/>
</DataTemplate>

<DataTemplate x:Key="headerTemplate1">
<TextBlock Text="Months" Padding="0,2,0,8" FontSize="14.5"/>
</DataTemplate>
</Grid.Resources>

<chart:SfChart Grid.Column="0">
<chart:SfChart.Header>
<TextBlock TextAlignment="Center" Text="Global Stock Trend" FontSize="17" Margin="0,10,0,10"/>
</chart:SfChart.Header>

<chart:SfChart.PrimaryAxis>
<chart:DateTimeAxis Interval="1" IntervalType="Months" LabelFormat="MMM" PlotOffset="30"
HeaderTemplate="{StaticResource headerTemplate1}" ShowGridLines="False">
<chart:DateTimeAxis.LabelStyle>
<chart:LabelStyle FontSize="13"/>
</chart:DateTimeAxis.LabelStyle>
</chart:DateTimeAxis>
</chart:SfChart.PrimaryAxis>

<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis Interval="10" Minimum="10" LabelFormat="$0" Maximum="80"
HeaderTemplate="{StaticResource headerTemplate2}">
<chart:NumericalAxis.LabelStyle>
<chart:LabelStyle FontSize="12.5"/>
</chart:NumericalAxis.LabelStyle>
</chart:NumericalAxis>
</chart:SfChart.SecondaryAxis>

<chart:ScatterSeries x:Name="series" ItemsSource="{Binding Data}" XBindingPath="Year" YBindingPath="Count"
ScatterHeight="50" ScatterWidth="50" CustomTemplate="{StaticResource seriesTemplate}">
<chart:ScatterSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo ShowLabel="True" SegmentLabelContent="LabelContentPath"
LabelTemplate="{StaticResource adornmentTemplate}"/>
</chart:ScatterSeries.AdornmentsInfo>
</chart:ScatterSeries>

</chart:SfChart>

<Canvas Name="drawingCanvas" Background="Transparent" Grid.Column="0"
MouseDown="OnMouseDown" MouseUp="OnMouseUp" Mouse.MouseMove="OnMouseMove"/>

<ListView Grid.Column="1" x:Name="listView" ItemsSource="{Binding SelectedDataPoints}" FontSize="16">
<ListView.View>
<GridView>
<GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year, StringFormat=d}"/>
<GridViewColumn Header="Count" DisplayMemberBinding="{Binding Count}"/>
<GridViewColumn Header="Variation" DisplayMemberBinding="{Binding Converter={StaticResource SymbolConverter}}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Border>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Syncfusion.UI.Xaml.Charts;
using System.Collections.ObjectModel;
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 MultipleSelection_ScatterPoints
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#region Fields

private Point startPoint;
private Rectangle? currentRectangle;
private Rect currentRect;

#endregion

#region Constructor

public MainWindow()
{
InitializeComponent();
}

#endregion

#region Methods

private void OnMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && currentRectangle != null)
{
// Update the size of the rectangle as the mouse is dragged
double width = e.GetPosition(drawingCanvas).X - startPoint.X;
double height = e.GetPosition(drawingCanvas).Y - startPoint.Y;
if (width > 0 && height > 0)
{
currentRect = new Rect(startPoint.X, startPoint.Y, width, height);
currentRectangle.Width = width;
currentRectangle.Height = height;
}
}
}

private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(drawingCanvas);

// Create a new rectangle
currentRectangle = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Fill = Brushes.Transparent
};

// Add the rectangle to the canvas
drawingCanvas.Children.Add(currentRectangle);

// Set the initial position of the rectangle
Canvas.SetLeft(currentRectangle, startPoint.X);
Canvas.SetTop(currentRectangle, startPoint.Y);
}

private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
viewModel.SelectedDataPoints = series.GetDataPoints(currentRect);
currentRectangle = null;
currentRect = Rect.Empty;
drawingCanvas.Children.Clear();
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultipleSelection_ScatterPoints
{
public class StockModel
{
public DateTime Year { get; set; }

public double Count { get; set; }

public double Variation { get; set; }

public StockModel(DateTime year, double count, double variation)
{
Year = year;
Count = count;
Variation = variation;
}
}
}
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>
Loading