main
syneffort 1 year ago
parent d0432955c5
commit 35c356a674
  1. 24
      LC_Tutorial/Tutorial/FinancialWindow.xaml
  2. 98
      LC_Tutorial/Tutorial/FinancialWindow.xaml.cs
  3. 1
      LC_Tutorial/Tutorial/MainWindow.xaml
  4. 6
      LC_Tutorial/Tutorial/MainWindow.xaml.cs

@ -0,0 +1,24 @@
<Window x:Class="Tutorial.FinancialWindow"
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:Tutorial"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="FinancialWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<lvc:CartesianChart Grid.Row="0" Series="{Binding SeriesCollection}" LegendLocation="Bottom">
<lvc:CartesianChart.AxisX>
<lvc:Axis Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<Button x:Name="btnUpdate" Grid.Row="1" Content="Update" Click="btnUpdate_Click"/>
</Grid>
</Window>

@ -0,0 +1,98 @@
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace Tutorial
{
/// <summary>
/// FinancialWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class FinancialWindow : Window, INotifyPropertyChanged
{
private string[] _labels;
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels
{
get { return _labels; }
set
{
_labels = value;
OnPropertyChanged(nameof(Labels));
}
}
public event PropertyChangedEventHandler? PropertyChanged;
public FinancialWindow()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
SeriesCollection = new SeriesCollection()
{
new OhlcSeries()
{
Values = new ChartValues<OhlcPoint>()
{
new OhlcPoint(32, 35, 30, 32),
new OhlcPoint(33, 38, 31, 37),
new OhlcPoint(35, 42, 30, 40),
new OhlcPoint(37, 40, 35, 38),
new OhlcPoint(35, 38, 32, 33)
}
},
new LineSeries()
{
Values = new ChartValues<double> {30, 32, 35, 30, 28},
Fill = Brushes.Transparent
}
};
Labels = new string[]
{
DateTime.Now.ToString("dd MMM"),
DateTime.Now.AddDays(1).ToString("dd MMM"),
DateTime.Now.AddDays(2).ToString("dd MMM"),
DateTime.Now.AddDays(3).ToString("dd MMM"),
DateTime.Now.AddDays(4).ToString("dd MMM"),
};
DataContext = this;
}
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
foreach (var point in SeriesCollection[0].Values.Cast<OhlcPoint>())
{
point.Open = rand.Next((int)point.Low, (int)point.High);
point.Close = rand.Next((int)point.Low, (int)point.High);
}
}
}
}

@ -20,6 +20,7 @@
<Button x:Name="btnStepLine" Content="Step Line" Margin="3" Click="btnStepLine_Click"/>
<Button x:Name="btnScatter" Content="Scatter" Margin="3" Click="btnScatter_Click"/>
<Button x:Name="btnBubble" Content="Bubble" Margin="3" Click="btnBubble_Click"/>
<Button x:Name="btnFinancial" Content="Financial" Margin="3" Click="btnFinancial_Click"/>
</StackPanel>
</Grid>
</Window>

@ -73,5 +73,11 @@ namespace Tutorial
BubbleWindow win = new BubbleWindow();
win.Show();
}
private void btnFinancial_Click(object sender, RoutedEventArgs e)
{
FinancialWindow win = new FinancialWindow();
win.Show();
}
}
}

Loading…
Cancel
Save