livechart line sample

main
syneffort 2 years ago
parent 557110d156
commit a2ac0de8f6
  1. 9
      PacticeSolution/LiveChartPractice/App.xaml
  2. 17
      PacticeSolution/LiveChartPractice/App.xaml.cs
  3. 10
      PacticeSolution/LiveChartPractice/AssemblyInfo.cs
  4. 14
      PacticeSolution/LiveChartPractice/LiveChartPractice.csproj
  5. 42
      PacticeSolution/LiveChartPractice/MainWindow.xaml
  6. 48
      PacticeSolution/LiveChartPractice/MainWindow.xaml.cs
  7. 45
      PacticeSolution/LiveChartPractice/SampleData.cs
  8. 10
      PacticeSolution/PacticeSolution.sln

@ -0,0 +1,9 @@
<Application x:Class="LiveChartPractice.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LiveChartPractice"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace LiveChartPractice
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -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)
)]

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiveCharts.Wpf.Core" Version="0.9.8" />
</ItemGroup>
</Project>

@ -0,0 +1,42 @@
<Window x:Class="LiveChartPractice.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:LiveChartPractice"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:SampleData/>
</Window.DataContext>
<Grid Margin="10">
<TabControl>
<TabItem Header="Lines">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<lvc:CartesianChart Grid.Row="0" Series="{Binding SeriesCollection}" LegendLocation="Right">
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"/>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Month" Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<Button x:Name="btnSeriesAdd" Grid.Row="1" Content="Add" Click="btnSeriesAdd_Click"/>
</Grid>
</TabItem>
<TabItem Header="Columns">
</TabItem>
<TabItem Header="StackedColumns">
</TabItem>
</TabControl>
</Grid>
</Window>

@ -0,0 +1,48 @@
using LiveCharts.Wpf;
using LiveCharts;
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.Navigation;
using System.Windows.Shapes;
namespace LiveChartPractice
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnSeriesAdd_Click(object sender, RoutedEventArgs e)
{
SampleData data = this.DataContext as SampleData;
if (data == null)
return;
Random rand = new Random();
data.SeriesCollection.Add(new LineSeries
{
Title = $"Series {data.SeriesCollection.Count + 1}",
Values = new ChartValues<double> { rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8), rand.Next(1, 8) },
LineSmoothness = rand.Next(0, 2), //0: straight lines, 1: really smooth lines
//PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
//PointGeometrySize = 50,
//PointForeground = Brushes.Gray
});
}
}
}

@ -0,0 +1,45 @@
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LiveChartPractice
{
public class SampleData
{
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> YFormatter { get; set; }
public SampleData()
{
this.SeriesCollection = new SeriesCollection()
{
new LineSeries()
{
Title = "Series 1",
Values = new ChartValues<double> { 4, 6, 5, 2, 4 }
},
new LineSeries()
{
Title = "Series 2",
Values = new ChartValues<double> { 6, 7, 3, 4 ,6 },
PointGeometry = null
},
new LineSeries()
{
Title = "Series 3",
Values = new ChartValues<double> { 4, 2, 7, 2, 7 },
PointGeometry = DefaultGeometries.Square,
PointGeometrySize = 15
},
};
this.Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May" };
this.YFormatter = value => value.ToString("C");
}
}
}

@ -133,9 +133,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimerAndWorker", "TimerAndW
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TreeViewSample", "TreeViewSample\TreeViewSample.csproj", "{CA88EE83-8C7F-4FEF-963A-DEACA5E502FB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TreeViewSample", "TreeViewSample\TreeViewSample.csproj", "{CA88EE83-8C7F-4FEF-963A-DEACA5E502FB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TriggerAnimations", "TriggerAnimations\TriggerAnimations.csproj", "{9D9FD436-C73C-4DB4-A311-09D2DB65E03E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TriggerAnimations", "TriggerAnimations\TriggerAnimations.csproj", "{9D9FD436-C73C-4DB4-A311-09D2DB65E03E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChartSample", "ChartSample\ChartSample.csproj", "{2052E6D4-43B5-4847-B629-B844E521C807}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChartSample", "ChartSample\ChartSample.csproj", "{2052E6D4-43B5-4847-B629-B844E521C807}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveChartPractice", "LiveChartPractice\LiveChartPractice.csproj", "{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -411,6 +413,10 @@ Global
{2052E6D4-43B5-4847-B629-B844E521C807}.Debug|Any CPU.Build.0 = Debug|Any CPU {2052E6D4-43B5-4847-B629-B844E521C807}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2052E6D4-43B5-4847-B629-B844E521C807}.Release|Any CPU.ActiveCfg = Release|Any CPU {2052E6D4-43B5-4847-B629-B844E521C807}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2052E6D4-43B5-4847-B629-B844E521C807}.Release|Any CPU.Build.0 = Release|Any CPU {2052E6D4-43B5-4847-B629-B844E521C807}.Release|Any CPU.Build.0 = Release|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save