syneffort 1 year ago
parent 2edc7dc8d5
commit fcfca60577
  1. 30
      LC_Tutorial/Tutorial/BasicPlots/RowsWindow.xaml
  2. 66
      LC_Tutorial/Tutorial/BasicPlots/RowsWindow.xaml.cs
  3. 1
      LC_Tutorial/Tutorial/MainWindow.xaml
  4. 6
      LC_Tutorial/Tutorial/MainWindow.xaml.cs

@ -0,0 +1,30 @@
<Window x:Class="Tutorial.BasicPlots.RowsWindow"
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.BasicPlots"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="RowsWindow" 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 Title="Salesman" LabelFormatter="{Binding Formatter}"/>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Apps" Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="SharedXValues"/>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
<Button x:Name="btnAdd" Grid.Row="1" Content="Add" Click="btnAdd_Click"/>
</Grid>
</Window>

@ -0,0 +1,66 @@
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
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.BasicPlots
{
/// <summary>
/// RowsWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class RowsWindow : Window
{
private int _offset = -10;
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
public RowsWindow()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
SeriesCollection = new SeriesCollection()
{
new RowSeries()
{
Title = DateTime.Now.AddYears(_offset++).Year.ToString(),
Values = new ChartValues<double> { 10, 50, 39, 50 }
}
};
Labels = new string[] { "Maria", "Susan", "Charles", "Frida" };
Formatter = value => value.ToString("N");
DataContext = this;
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
SeriesCollection.Add(new RowSeries()
{
Title = DateTime.Now.AddYears(_offset++).Year.ToString(),
Values = new ChartValues<double> { (double)rand.Next(0, 50), (double)rand.Next(0, 50), (double)rand.Next(0, 50) }
});
SeriesCollection[SeriesCollection.Count - 1].Values.Add((double)rand.Next(0, 50));
}
}
}

@ -15,6 +15,7 @@
<Button x:Name="btnLines" Content="Lines" Margin="3" Click="btnLines_Click"/>
<Button x:Name="btnColumns" Content="Columns" Margin="3" Click="btnColumns_Click"/>
<Button x:Name="btnStackedColumns" Content="Stacked Columns" Margin="3" Click="btnStackedColumns_Click"/>
<Button x:Name="btnRows" Content="Rows" Margin="3" Click="btnRows_Click"/>
</StackPanel>
</Grid>
</Window>

@ -43,5 +43,11 @@ namespace Tutorial
StackedColumnsWindow win = new StackedColumnsWindow();
win.Show();
}
private void btnRows_Click(object sender, RoutedEventArgs e)
{
RowsWindow win = new RowsWindow();
win.Show();
}
}
}

Loading…
Cancel
Save