项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,20 @@
<UserControl x:Class="Wpf.CartesianChart.Basic_Bars.BasicColumn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Basic_Bars"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:BasicColumn}">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Left">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Salesman" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,44 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Basic_Bars
{
public partial class BasicColumn : UserControl
{
public BasicColumn()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new ColumnSeries
{
Title = "2015",
Values = new ChartValues<double> { 10, 50, 39, 50 }
}
};
//adding series will update and animate the chart automatically
SeriesCollection.Add(new ColumnSeries
{
Title = "2016",
Values = new ChartValues<double> { 11, 56, 42 }
});
//also adding values updates and animates the chart automatically
SeriesCollection[1].Values.Add(48d);
Labels = new[] {"Maria", "Susan", "Charles", "Frida"};
Formatter = value => value.ToString("N");
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="Wpf.CartesianChart.Basic_Bars.BasicRowExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Basic_Bars"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:BasicRowExample}">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Bottom">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Salesman" LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Apps" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,44 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Basic_Bars
{
public partial class BasicRowExample : UserControl
{
public BasicRowExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new RowSeries
{
Title = "2015",
Values = new ChartValues<double> { 10, 50, 39, 50 }
}
};
//adding series will update and animate the chart automatically
SeriesCollection.Add(new RowSeries
{
Title = "2016",
Values = new ChartValues<double> { 11, 56, 42}
});
//also adding values updates and animates the chart automatically
SeriesCollection[1].Values.Add(48d);
Labels = new[] {"Maria", "Susan", "Charles", "Frida"};
Formatter = value => value.ToString("N");
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
<UserControl x:Class="Wpf.CartesianChart.Basic_Stacked_Bar.BasicStackedColumnExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Bottom">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Browser"
Labels="{Binding Labels}"
Separator="{x:Static lvc:DefaultAxes.CleanSeparator}" />
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Usage" LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,54 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Basic_Stacked_Bar
{
/// <summary>
/// Interaction logic for StackedColumnExample.xaml
/// </summary>
public partial class BasicStackedColumnExample : UserControl
{
public BasicStackedColumnExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new StackedColumnSeries
{
Values = new ChartValues<double> {4, 5, 6, 8},
StackMode = StackMode.Values, // this is not necessary, values is the default stack mode
DataLabels = true
},
new StackedColumnSeries
{
Values = new ChartValues<double> {2, 5, 6, 7},
StackMode = StackMode.Values,
DataLabels = true
}
};
//adding series updates and animates the chart
SeriesCollection.Add(new StackedColumnSeries
{
Values = new ChartValues<double> {6, 2, 7},
StackMode = StackMode.Values
});
//adding values also updates and animates
SeriesCollection[2].Values.Add(4d);
Labels = new[] {"Chrome", "Mozilla", "Opera", "IE"};
Formatter = value => value + " Mill";
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="Wpf.CartesianChart.Basic_Stacked_Bar.BasicStackedRowPercentageExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Basic_Stacked_Bar"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Top">
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Browser" Labels="{Binding Labels}" />
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Formatter}" />
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,58 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Basic_Stacked_Bar
{
/// <summary>
/// Interaction logic for BasicStackedRowPercentageExample.xaml
/// </summary>
public partial class BasicStackedRowPercentageExample : UserControl
{
public BasicStackedRowPercentageExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new StackedRowSeries
{
Values = new ChartValues<double> {4, 5, 6, 8},
StackMode = StackMode.Percentage,
DataLabels = true,
LabelPoint = p => p.X.ToString()
},
new StackedRowSeries
{
Values = new ChartValues<double> {2, 5, 6, 7},
StackMode = StackMode.Percentage,
DataLabels = true,
LabelPoint = p => p.X.ToString()
}
};
//adding series updates and animates the chart
SeriesCollection.Add(new StackedRowSeries
{
Values = new ChartValues<double> { 6, 2, 7 },
StackMode = StackMode.Percentage,
DataLabels = true,
LabelPoint = p => p.X.ToString()
});
//adding values also updates and animates
SeriesCollection[2].Values.Add(4d);
Labels = new[] { "Chrome", "Mozilla", "Opera", "IE" };
Formatter = val => val.ToString("P");
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
<UserControl x:Class="Wpf.CartesianChart.BasicLine.BasicLineExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.BasicLine"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Right" >
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Month" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,49 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.BasicLine
{
public partial class BasicLineExample : UserControl
{
public BasicLineExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = new ChartValues<double> { 4, 6, 5, 2 ,7 }
},
new LineSeries
{
Title = "Series 2",
Values = new ChartValues<double> { 6, 7, 3, 4 ,6 }
}
};
Labels = new[] {"Jan", "Feb", "Mar", "Apr", "May"};
YFormatter = value => value.ToString("C");
//modifying the series collection will animate and update the chart
SeriesCollection.Add(new LineSeries
{
Values = new ChartValues<double> {5, 3, 2, 4},
LineSmoothness = 0 //straight lines, 1 really smooth lines
});
//modifying any series values will also animate and update the chart
SeriesCollection[2].Values.Add(5d);
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> YFormatter { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
<UserControl x:Class="Wpf.CartesianChart.Bubbles.BubblesExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Click="UpdateAllOnClick">
Move All
</Button>
<lvc:CartesianChart Grid.Row="1" Series="{Binding SeriesCollection}">
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,66 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Bubbles
{
public partial class BubblesExample : UserControl
{
public BubblesExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new ScatterSeries
{
Values = new ChartValues<ScatterPoint>
{
new ScatterPoint(5, 5, 20),
new ScatterPoint(3, 4, 80),
new ScatterPoint(7, 2, 20),
new ScatterPoint(2, 6, 60),
new ScatterPoint(8, 2, 70)
},
MinPointShapeDiameter = 15,
MaxPointShapeDiameter = 45
},
new ScatterSeries
{
Values = new ChartValues<ScatterPoint>
{
new ScatterPoint(7, 5, 1),
new ScatterPoint(2, 2, 1),
new ScatterPoint(1, 1, 1),
new ScatterPoint(6, 3, 1),
new ScatterPoint(8, 8, 1)
},
PointGeometry = DefaultGeometries.Triangle,
MinPointShapeDiameter = 15,
MaxPointShapeDiameter = 45
}
};
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var series in SeriesCollection)
{
foreach (var bubble in series.Values.Cast<ScatterPoint>())
{
bubble.X = r.NextDouble()*10;
bubble.Y = r.NextDouble()*10;
bubble.Weight = r.NextDouble()*10;
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Wpf.CartesianChart.Chart_to_Image.ChartToImageSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Chart_to_Image"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Click="BuildPngOnClick">Build Png</Button>
</Grid>
</UserControl>

View File

@@ -0,0 +1,63 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Chart_to_Image
{
/// <summary>
/// Interaction logic for ChartToImageSample.xaml
/// </summary>
public partial class ChartToImageSample : UserControl
{
public ChartToImageSample()
{
InitializeComponent();
}
private void BuildPngOnClick(object sender, RoutedEventArgs e)
{
var myChart = new LiveCharts.Wpf.CartesianChart
{
DisableAnimations = true,
Width = 600,
Height = 200,
Series = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<double> {1, 6, 7, 2, 9, 3, 6, 5}
}
}
};
var viewbox = new Viewbox();
viewbox.Child = myChart;
viewbox.Measure(myChart.RenderSize);
viewbox.Arrange(new Rect(new Point(0, 0), myChart.RenderSize));
myChart.Update(true, true); //force chart redraw
viewbox.UpdateLayout();
SaveToPng(myChart, "chart.png");
//png file was created at the root directory.
}
private void SaveToPng(FrameworkElement visual, string fileName)
{
var encoder = new PngBitmapEncoder();
EncodeVisual(visual, fileName, encoder);
}
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
{
var bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(visual);
var frame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(frame);
using (var stream = File.Create(fileName)) encoder.Save(stream);
}
}
}

View File

@@ -0,0 +1,40 @@
<UserControl x:Class="Wpf.CartesianChart.ConstantChanges.ConstantChangesChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:constantChanges="clr-namespace:Wpf.CartesianChart.ConstantChanges"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance constantChanges:ConstantChangesChart}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Click="InjectStopOnClick">
Inject/Stop Data
</Button>
<!--Here we disable tooltips and hovering to get a better performance-->
<lvc:CartesianChart Grid.Row="1" AnimationsSpeed="0:0:0.5" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding ChartValues}"
PointGeometry="{x:Null}"
LineSmoothness="1"
StrokeThickness="6"
Stroke="#F34336"
Fill="Transparent"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}"
MaxValue="{Binding AxisMax}"
MinValue="{Binding AxisMin}"
Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,135 @@
using System;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Configurations;
namespace Wpf.CartesianChart.ConstantChanges
{
public partial class ConstantChangesChart : UserControl, INotifyPropertyChanged
{
private double _axisMax;
private double _axisMin;
private double _trend;
public ConstantChangesChart()
{
InitializeComponent();
//To handle live data easily, in this case we built a specialized type
//the MeasureModel class, it only contains 2 properties
//DateTime and Value
//We need to configure LiveCharts to handle MeasureModel class
//The next code configures MeasureModel globally, this means
//that LiveCharts learns to plot MeasureModel and will use this config every time
//a IChartValues instance uses this type.
//this code ideally should only run once
//you can configure series in many ways, learn more at
//http://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration
var mapper = Mappers.Xy<MeasureModel>()
.X(model => model.DateTime.Ticks) //use DateTime.Ticks as X
.Y(model => model.Value); //use the value property as Y
//lets save the mapper globally.
Charting.For<MeasureModel>(mapper);
//the values property will store our values array
ChartValues = new ChartValues<MeasureModel>();
//lets set how to display the X Labels
DateTimeFormatter = value => new DateTime((long) value).ToString("mm:ss");
//AxisStep forces the distance between each separator in the X axis
AxisStep = TimeSpan.FromSeconds(1).Ticks;
//AxisUnit forces lets the axis know that we are plotting seconds
//this is not always necessary, but it can prevent wrong labeling
AxisUnit = TimeSpan.TicksPerSecond;
SetAxisLimits(DateTime.Now);
//The next code simulates data changes every 300 ms
IsReading = false;
DataContext = this;
}
public ChartValues<MeasureModel> ChartValues { get; set; }
public Func<double, string> DateTimeFormatter { get; set; }
public double AxisStep { get; set; }
public double AxisUnit { get; set; }
public double AxisMax
{
get { return _axisMax; }
set
{
_axisMax = value;
OnPropertyChanged("AxisMax");
}
}
public double AxisMin
{
get { return _axisMin; }
set
{
_axisMin = value;
OnPropertyChanged("AxisMin");
}
}
public bool IsReading { get; set; }
private void Read()
{
var r = new Random();
while (IsReading)
{
Thread.Sleep(150);
var now = DateTime.Now;
_trend += r.Next(-8, 10);
ChartValues.Add(new MeasureModel
{
DateTime = now,
Value = _trend
});
SetAxisLimits(now);
//lets only use the last 150 values
if (ChartValues.Count > 150) ChartValues.RemoveAt(0);
}
}
private void SetAxisLimits(DateTime now)
{
AxisMax = now.Ticks + TimeSpan.FromSeconds(1).Ticks; // lets force the axis to be 1 second ahead
AxisMin = now.Ticks - TimeSpan.FromSeconds(8).Ticks; // and 8 seconds behind
}
private void InjectStopOnClick(object sender, RoutedEventArgs e)
{
IsReading = !IsReading;
if (IsReading) Task.Factory.StartNew(Read);
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
using System;
namespace Wpf.CartesianChart.ConstantChanges
{
public class MeasureModel
{
public DateTime DateTime { get; set; }
public double Value { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
<UserControl x:Class="Wpf.CartesianChart.CustomTooltipAndLegend.CustomTooltipAndLegendExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:Wpf.CartesianChart.CustomTooltipAndLegend"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:CustomTooltipAndLegendExample}">
<Grid>
<lvc:CartesianChart LegendLocation="Right">
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Title="2016 Customers" Values="{Binding Customers}"></lvc:ColumnSeries>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX >
<lvc:Axis Labels="{Binding Labels}" LabelsRotation="-15">
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.DataTooltip>
<local:CustomersTooltip/>
</lvc:CartesianChart.DataTooltip>
<lvc:CartesianChart.ChartLegend>
<local:CustomersLegend></local:CustomersLegend>
</lvc:CartesianChart.ChartLegend>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,68 @@
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Configurations;
namespace Wpf.CartesianChart.CustomTooltipAndLegend
{
public partial class CustomTooltipAndLegendExample : UserControl
{
public CustomTooltipAndLegendExample()
{
InitializeComponent();
Customers = new ChartValues<CustomerVm>
{
new CustomerVm
{
Name = "Irvin",
LastName = "Hale",
Phone = 123456789,
PurchasedItems = 8
},
new CustomerVm
{
Name = "Malcolm",
LastName = "Revees",
Phone = 098765432,
PurchasedItems = 3
},
new CustomerVm
{
Name = "Anne",
LastName = "Rios",
Phone = 758294026,
PurchasedItems = 6
},
new CustomerVm
{
Name = "Vivian",
LastName = "Howell",
Phone = 309382739,
PurchasedItems = 3
},
new CustomerVm
{
Name = "Caleb",
LastName = "Roy",
Phone = 682902826,
PurchasedItems = 2
}
};
Labels = new[] { "Irvin", "Malcolm", "Anne", "Vivian", "Caleb" };
//let create a mapper so LiveCharts know how to plot our CustomerViewModel class
var customerVmMapper = Mappers.Xy<CustomerVm>()
.X((value, index) => index) // lets use the position of the item as X
.Y(value => value.PurchasedItems); //and PurchasedItems property as Y
//lets save the mapper globally
Charting.For<CustomerVm>(customerVmMapper);
DataContext = this;
}
public ChartValues<CustomerVm> Customers { get; set; }
public string[] Labels { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace Wpf.CartesianChart.CustomTooltipAndLegend
{
public class CustomerVm
{
public string Name { get; set; }
public string LastName { get; set; }
public int Phone { get; set; }
public int PurchasedItems { get; set; }
}
}

View File

@@ -0,0 +1,26 @@
<UserControl x:Class="Wpf.CartesianChart.CustomTooltipAndLegend.CustomersLegend"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.CustomTooltipAndLegend"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Background="#555555" BorderThickness="2" Padding="20 10" BorderBrush="AntiqueWhite"
d:DataContext="{d:DesignInstance local:CustomersLegend}">
<ItemsControl ItemsSource="{Binding Series}" Grid.IsSharedSizeScope="True">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type lvc:SeriesViewModel}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Title"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Stroke="{Binding Stroke}" Fill="{Binding Fill}"
Width="15" Height="15"/>
<TextBlock Grid.Column="1" Margin="4 0" Text="{Binding Title}" Foreground="White" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Controls;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.CustomTooltipAndLegend
{
public partial class CustomersLegend : UserControl, IChartLegend
{
private List<SeriesViewModel> _series;
public CustomersLegend()
{
InitializeComponent();
DataContext = this;
}
public List<SeriesViewModel> Series
{
get { return _series; }
set
{
_series = value;
OnPropertyChanged("Series");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,39 @@
<UserControl x:Class="Wpf.CartesianChart.CustomTooltipAndLegend.CustomersTooltip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:Wpf.CartesianChart.CustomTooltipAndLegend"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
d:DataContext="{d:DesignInstance local:CustomersTooltip}"
Background="#E4555555" Padding="20 10" BorderThickness="2" BorderBrush="#555555">
<ItemsControl ItemsSource="{Binding Data.Points}" Grid.IsSharedSizeScope="True">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type wpf:DataPointViewModel}">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Title"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="LastName"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Phone"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="PurchasedItems"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Stroke="{Binding Series.Stroke}" Fill="{Binding Series.Fill}"
Height="15" Width="15"></Rectangle>
<TextBlock Grid.Column="1" Text="{Binding ChartPoint.Instance.(local:CustomerVm.Name)}"
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Grid.Column="2" Text="{Binding ChartPoint.Instance.(local:CustomerVm.LastName)}"
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Grid.Column="3" Text="{Binding ChartPoint.Instance.(local:CustomerVm.Phone),
StringFormat=Phone: {0}}"
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Grid.Column="4" Text="{Binding ChartPoint.Instance.(local:CustomerVm.PurchasedItems),
StringFormat=Purchased Items: {0:N}}"
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>

View File

@@ -0,0 +1,41 @@
using System.ComponentModel;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.CustomTooltipAndLegend
{
public partial class CustomersTooltip : IChartTooltip
{
private TooltipData _data;
public CustomersTooltip()
{
InitializeComponent();
//LiveCharts will inject the tooltip data in the Data property
//your job is only to display this data as required
DataContext = this;
}
public event PropertyChangedEventHandler PropertyChanged;
public TooltipData Data
{
get { return _data; }
set
{
_data = value;
OnPropertyChanged("Data");
}
}
public TooltipSelectionMode? SelectionMode { get; set; }
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,21 @@
<UserControl x:Class="Wpf.CartesianChart.CustomZoomingAndPanning.MoveMe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.CustomZoomingAndPanning"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:MoveMe}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding SeriesValues}" StrokeThickness="4" PointDiameter="18" />
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,51 @@
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;
using LiveCharts;
namespace Wpf.CartesianChart.CustomZoomingAndPanning
{
/// <summary>
/// Interaction logic for MoveMe.xaml
/// </summary>
public partial class MoveMe : UserControl
{
public MoveMe()
{
InitializeComponent();
SeriesValues = GetData();
DataContext = this;
}
public ChartValues<double> SeriesValues { get; set; }
private ChartValues<double> GetData()
{
var r = new Random();
var trend = 100;
var values = new ChartValues<double>();
for (var i = 0; i < 160; i++)
{
var seed = r.NextDouble();
if (seed > .8) trend += seed > .9 ? 50 : -50;
values.Add(trend + r.Next(0, 10));
}
return values;
}
}
}

View File

@@ -0,0 +1,60 @@
<UserControl x:Class="Wpf.CartesianChart.Customized_Line_Series.CustomizedLineSeries"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:customizedLineSeries="clr-namespace:Wpf.CartesianChart.Customized_Line_Series"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance customizedLineSeries:CustomizedLineSeries }">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Margin="20" Click="MoveOnClick">Move</Button>
<lvc:CartesianChart Grid.Row="2" Background="#222E31">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding Values1}" StrokeThickness="4" StrokeDashArray="2"
Stroke="#6BBA45" Fill="Transparent" LineSmoothness="0" PointGeometrySize="20"
PointGeometry="{x:Static lvc:DefaultGeometries.Diamond}"
PointForeground="#6BBA45"/>
<lvc:LineSeries Values="{Binding Values2}" StrokeThickness="2"
Stroke="#1C8FC5" Fill="Transparent" LineSmoothness="1"
PointGeometrySize="15" PointForeground="#222E31"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.VisualElements>
<lvc:VisualElement X="0.5" Y="8">
<lvc:VisualElement.UIElement>
<TextBlock Foreground="White">
Hello!, this is a note merged in the chart.
</TextBlock>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
</lvc:CartesianChart.VisualElements>
<lvc:CartesianChart.AxisX>
<lvc:Axis IsMerged="True">
<lvc:Axis.Separator>
<lvc:Separator StrokeThickness="1" StrokeDashArray="2">
<lvc:Separator.Stroke>
<SolidColorBrush Color="#404F56" />
</lvc:Separator.Stroke>
</lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis IsMerged="True">
<lvc:Axis.Separator>
<lvc:Separator StrokeThickness="1.5" StrokeDashArray="4">
<lvc:Separator.Stroke>
<SolidColorBrush Color="#404F56" />
</lvc:Separator.Stroke>
</lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,58 @@
using System;
using System.Linq;
using System.Windows;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Customized_Line_Series
{
/// <summary>
/// Interaction logic for CustomizedExample.xaml
/// </summary>
public partial class CustomizedLineSeries
{
public CustomizedLineSeries()
{
InitializeComponent();
Values1 = new ChartValues<ObservableValue>
{
new ObservableValue(3),
new ObservableValue(4),
new ObservableValue(6),
new ObservableValue(3),
new ObservableValue(2),
new ObservableValue(6)
};
Values2 = new ChartValues<ObservableValue>
{
new ObservableValue(5),
new ObservableValue(3),
new ObservableValue(5),
new ObservableValue(7),
new ObservableValue(3),
new ObservableValue(9)
};
DataContext = this;
}
public ChartValues<ObservableValue> Values1 { get; set; }
public ChartValues<ObservableValue> Values2 { get; set; }
private void MoveOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var value in Values1)
{
value.Value = r.Next(0, 10);
}
foreach (var value in Values2)
{
value.Value = r.Next(0, 10);
}
}
}
}

View File

@@ -0,0 +1,59 @@
<UserControl x:Class="Wpf.CartesianChart.DataLabelTemplate.DataLabelTemplateSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.Resources>
<Style TargetType="lvc:ColumnSeries">
<Setter Property="MaxColumnWidth" Value="9999"></Setter>
<Setter Property="ColumnPadding" Value="30"></Setter>
<Setter Property="DataLabels" Value="True"></Setter>
</Style>
</Grid.Resources>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Fill="#F34336" StrokeThickness="0"
Values="6" Title="Chrome">
<lvc:ColumnSeries.DataLabelsTemplate>
<DataTemplate>
<Path Data="M255,0C114.75,0,0,114.75,0,255s114.75,255,255,255s255-114.75,255-255S395.25,0,255,0z M255,51 c76.5,0,140.25,40.8,175.95,102H255c-48.45,0-91.8,35.7-99.45,81.6l-61.2-104.55C132.6,81.6,188.7,51,255,51z M331.5,255 c0,43.35-33.15,76.5-76.5,76.5c-43.35,0-76.5-33.15-76.5-76.5c0-43.35,33.15-76.5,76.5-76.5C298.35,178.5,331.5,211.65,331.5,255z M51,255c0-38.25,10.2-71.4,28.05-102l89.25,153l0,0c17.85,30.6,51,51,86.7,51c12.75,0,22.95-2.55,33.15-5.1l-61.2,104.55 C127.5,443.7,51,357,51,255z M255,459l89.25-153l0,0c7.65-15.3,15.3-33.15,15.3-51c0-30.6-12.75-58.65-35.7-76.5h122.4 c10.2,22.95,15.3,48.45,15.3,76.5C459,367.2,367.2,459,255,459z"
Fill="#C9372D" Height="40" Width="40" Stretch="Fill"/>
</DataTemplate>
</lvc:ColumnSeries.DataLabelsTemplate>
</lvc:ColumnSeries>
<lvc:ColumnSeries Fill="#2195F2" StrokeThickness="0"
Values="8" Title="Mozilla">
<lvc:ColumnSeries.DataLabelsTemplate>
<DataTemplate>
<Path Data="M301.98,103.88c-1.108-0.17-2.194,0.421-2.656,1.442l-3.413,7.555c-1.296-9.931-3.7-25.915-6.875-36.396 c-4.839-16.138-15.087-26.571-15.521-27.008c-0.785-0.789-1.995-0.964-2.973-0.43c-0.976,0.534-1.482,1.649-1.24,2.735 l2.652,11.949c-6.381-6.666-16.632-16.234-26.776-20.898c-2.439-1.189-4.918-2.279-7.089-3.219 c-22.038-19.576-50.3-30.352-79.627-30.352c-41.3,0-78.94,20.689-101.226,55.487c-2.097-1.694-5.037-4.657-6.722-8.928 c-3.064-7.512-4.616-15.951-4.632-16.035c-0.165-0.906-0.813-1.648-1.689-1.932c-0.874-0.284-1.836-0.064-2.501,0.573 C23.326,56.034,25.149,83.49,25.834,89.713c-2.276,2.431-8.709,9.639-15.208,20.038c-8.07,12.921-10.513,35.509-10.612,36.464 c-0.111,1.066,0.468,2.084,1.441,2.532c0.977,0.448,2.126,0.225,2.86-0.553l5.375-5.678c-0.586,2.173-1.176,4.65-1.721,7.424 c-2.421,11.975-1.713,30.55-1.682,31.335c0.046,1.15,0.871,2.121,2,2.35c1.128,0.232,2.267-0.341,2.759-1.382l3.163-6.697 c2.332,16.302,11.285,50.988,45.614,82.941c25.426,23.684,60.79,37.269,97.025,37.271c0.004,0,0.005,0,0.009,0 c35.168,0,68.374-12.578,96.022-36.372c32.692-28.164,44.871-68.384,49.33-97.166c4.814-31.073,1.996-55.158,1.873-56.168 C303.949,104.938,303.09,104.05,301.98,103.88z M246.16,104.785c0.034,0.044,3.426,4.486,4.166,15.868 c0.51,8.518-1.238,22.14-2.341,29.593l-6.661-7.729c-0.719-0.834-1.896-1.102-2.904-0.655c-1.007,0.445-1.604,1.496-1.471,2.588 c0.023,0.192,2.293,19.437-1.526,36.165c-1.808,7.861-4.637,13.512-7.064,17.241l0.931-12.6c0.089-1.209-0.701-2.307-1.876-2.606 c-1.176-0.301-2.396,0.286-2.895,1.391c-0.112,0.249-11.658,25.037-43.279,34.852c-4.416,1.36-9.067,2.05-13.825,2.05 c-16.854,0.001-32.168-8.598-40.849-14.64c0.747,0.038,1.49,0.057,2.229,0.057c12.435,0,21.998-5.357,29.684-9.662 c2.019-1.131,3.926-2.199,5.761-3.106c11.045-5.554,16.18-6.02,20.125-6.02c2.084,0,3.691-1.217,4.195-3.175 c1.235-4.806-4.543-13.372-11.678-17.3c-3.539-1.924-7.323-2.82-11.906-2.82c-7.292,0-16.333,2.3-29.284,5.806 c-2.377,0.634-4.724,0.956-6.976,0.956c-7.936,0.001-13.184-3.838-16.189-7.059c-4.044-4.334-6.347-10.061-6.008-14.945 c0.154-2.227,1.026-4.504,6.325-4.504c4.701,0,9.926,1.938,9.977,1.956c0.285,0.108,0.584,0.161,0.881,0.161 c0.005,0,0.012,0,0.019,0c1.381,0,2.5-1.119,2.5-2.5c0-0.135-0.011-0.268-0.031-0.397l-0.699-21.899 c2.525-1.61,8.567-5.527,14.375-9.749c14.051-10.214,15.933-14.12,14.429-17.087c-1.992-4.04-7.235-4.696-13.306-5.456 c-3.474-0.435-7.411-0.928-10.967-2.105c-7.408-2.462-12.289-8.858-13.4-10.43c-0.23-1.316-0.78-5.75,1.395-9.535 c2.354-4.137,10.495-10.542,13.434-12.662c0.84-0.605,1.22-1.666,0.955-2.667c-0.265-1-1.119-1.735-2.148-1.846 c-0.252-0.028-7.721-0.774-19.922,3.266c-9.934,3.328-17.639,8.722-20.294,10.723c-1.142-0.224-3.097-0.533-6.336-0.867 c19.025-21.484,46.01-33.714,74.76-33.714c21.101,0,41.038,6.417,58.012,18.618l-16.808,2.811 c-1.142,0.191-2.003,1.141-2.082,2.295c-0.079,1.155,0.646,2.213,1.75,2.558c0.224,0.07,22.608,7.146,39.31,20.021 c3.717,2.909,7.115,6.676,10.104,11.199c2.787,5.974,4.968,12.134,6.513,18.387l-5.62-4.367c-0.998-0.775-2.406-0.672-3.296,0.223 C245.454,102.361,245.38,103.792,246.16,104.785z"
Fill="#1A73BB" Height="40" Width="40" Stretch="Fill"/>
</DataTemplate>
</lvc:ColumnSeries.DataLabelsTemplate>
</lvc:ColumnSeries>
<lvc:ColumnSeries Fill="#4CAF50" StrokeThickness="0"
Values="2" Title="Explorer">
<lvc:ColumnSeries.DataLabelsTemplate>
<DataTemplate>
<Path Data="M179.649,292.487c0,17.067,7.186,31.439,15.27,46.709c8.982,16.168,21.558,28.744,37.726,38.625 s33.235,14.372,52.996,14.372c18.863,0,36.828-4.491,52.996-14.372c16.168-9.881,27.846-24.253,37.726-40.421h125.754 c-16.168,45.811-44.014,85.333-84.435,114.077s-85.333,44.014-134.737,44.014c-36.828,0-72.758-8.084-105.095-24.253 c-73.656,35.93-126.653,37.726-158.989,5.389C5.389,465.848,0,447.883,0,423.631s4.491-52.098,14.372-81.74 c9.881-30.54,25.151-62.877,47.607-99.705c17.067-28.744,29.642-51.2,78.147-97.909c17.965-17.965,26.049-26.947,30.54-31.439 c-43.116,20.66-98.807,59.284-143.719,98.807c26.947-66.47,64.674-100.604,110.484-129.347 c49.404-29.642,89.825-49.404,143.719-49.404c5.389,0,10.779,0,17.067,0.898C337.74,15.827,373.67,6.845,406.007,4.15 c32.337-1.796,54.793,3.593,68.267,16.168c26.947,26.947,28.744,70.063,7.186,128.449c20.66,35.93,21.558,76.351,21.558,117.67 c0,9.881,0.898,18.863,0,26.947H386.246H179.649V292.487z"
Fill="#3B873E" Height="40" Width="40" Stretch="Fill"/>
</DataTemplate>
</lvc:ColumnSeries.DataLabelsTemplate>
</lvc:ColumnSeries>
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
<!--
Credit:
Icons made by:
Google: Google (http://www.flaticon.com/authors/google),
Mozilla: Freepik (http://www.freepik.com),
Explorer: Madebyoliver (http://www.flaticon.com/authors/madebyoliver)
from www.flaticon.com is licensed by CC 3.0 BY (http://creativecommons.org/licenses/by/3.0/)
-->
</UserControl>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
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 Wpf.CartesianChart.DataLabelTemplate
{
/// <summary>
/// Interaction logic for DataLabelTemplateSample.xaml
/// </summary>
public partial class DataLabelTemplateSample : UserControl
{
public DataLabelTemplateSample()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,70 @@
<UserControl x:Class="Wpf.CartesianChart.DateAxis.DateAxisExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Background="#FFC107" HorizontalAlignment="Right" Padding="10 5" FontWeight="Bold">Experimental</TextBlock>
<StackPanel Grid.Row="1">
<Label>Set `DateAxis.InitialDateTime` to configure the starting point (X=0) dateTime.</Label>
<Label>Configure the DateAxis.Period to the PeriodUnit of your axis values. Use the buttons below to configure this property for the X axis.</Label>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Button Click="SetMilliSecondPeriod">
Millisecond
</Button>
<Button Click="SetSecondPeriod">
Second
</Button>
<Button Click="SetMinutePeriod">
Minute
</Button>
<Button Click="SetHourPeriod">
Hour
</Button>
<Button Click="SetDayPeriod">
Day
</Button>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Label Content="Series Period: "></Label>
<Label Content="{Binding Period}"></Label>
<Label Content="Seperator window: "></Label>
<Label Content="{Binding SelectedWindow, Mode=TwoWay}"></Label>
</StackPanel>
<lvc:CartesianChart Zoom="X" Grid.Row="4" DisableAnimations="False" Series="{Binding SeriesCollection}">
<lvc:CartesianChart.AxisX>
<lvc:DateAxis
MinValue="0"
MaxValue="60"
Foreground="DarkSlateBlue"
HeaderForeground="Black"
Period="{Binding Period, Mode=TwoWay}"
ShowLabels="True"
SelectedWindow="{Binding SelectedWindow, Mode=TwoWay}"
InitialDateTime="{Binding InitialDateTime}">
<lvc:DateAxis.Separator>
<lvc:Separator StrokeThickness="10" Stroke="Black"/>
</lvc:DateAxis.Separator>
</lvc:DateAxis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,104 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Helpers;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.DateAxis
{
public partial class DateAxisExample : UserControl, INotifyPropertyChanged
{
private DateTime _initialDateTime;
private PeriodUnits _period = PeriodUnits.Days;
private IAxisWindow _selectedWindow;
public DateAxisExample()
{
InitializeComponent();
var now = DateTime.UtcNow;
InitialDateTime = new DateTime(now.Year, now.Month, now.Day);
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = new ChartValues<double> { 4, 6, 5, 2 ,7, 8, 2, 0, 3, 5, 2, 4, 6, 4, 7, 3, 10, 4, 1, 2, 5, 8, 4, 6, 2, 4, 8, 7, 5, 4, 3, 2, 5, 6, 5, 3, 6, 4, 6, 3, 4, 1, 4, 2, 3, 2, 3, 5, 8, 6, 8, 4, 2, 4, 1, 2, 5, 6, 4, 6, 5, 2 ,7, 8, 2, 0, 3, 5, 2, 4, 6, 4, 7, 3, 10, 4, 1, 2, 5, 8, 4, 6, 2, 4, 8, 7, 5, 4, 3, 2, 5, 6, 5, 3, 6, 4, 6, 3, 4, 1, 4, 2, 3, 2, 3, 5, 8, 6, 8, 4, 2, 4, 1, 2, 5, 6 },
},
};
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public DateTime InitialDateTime
{
get { return _initialDateTime; }
set
{
_initialDateTime = value;
OnPropertyChanged("InitialDateTime");
}
}
public PeriodUnits Period
{
get { return _period; }
set
{
_period = value;
OnPropertyChanged("Period");
}
}
public IAxisWindow SelectedWindow
{
get { return _selectedWindow; }
set
{
_selectedWindow = value;
OnPropertyChanged("SelectedWindow");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void SetDayPeriod(object sender, RoutedEventArgs e)
{
Period = PeriodUnits.Days;
}
private void SetHourPeriod(object sender, RoutedEventArgs e)
{
Period = PeriodUnits.Hours;
}
private void SetMinutePeriod(object sender, RoutedEventArgs e)
{
Period = PeriodUnits.Minutes;
}
private void SetSecondPeriod(object sender, RoutedEventArgs e)
{
Period = PeriodUnits.Seconds;
}
private void SetMilliSecondPeriod(object sender, RoutedEventArgs e)
{
Period = PeriodUnits.Milliseconds;
}
}
}

View File

@@ -0,0 +1,44 @@
<UserControl x:Class="Wpf.CartesianChart.DynamicVisibility.DynamicVisibilityExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:dynamicVisibility="clr-namespace:Wpf.CartesianChart.DynamicVisibility"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance dynamicVisibility:DynamicVisibilityExample}">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="bvc"></BooleanToVisibilityConverter>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding MariaSeriesVisibility}">
Maria Series
</CheckBox>
<CheckBox IsChecked="{Binding CharlesSeriesVisibility}">
Charles Series
</CheckBox>
<CheckBox IsChecked="{Binding JohnSeriesVisibility}">
John Series
</CheckBox>
</StackPanel>
<lvc:CartesianChart Grid.Row="1" Hoverable="False">
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Title="Maria" Values="4,7,2,9,3" Visibility="{Binding MariaSeriesVisibility, Converter={StaticResource bvc}}" MaxWidth="1000" ColumnPadding="0"/>
<lvc:ColumnSeries Title="Charles" Values="6,2,6,3,8" Visibility="{Binding CharlesSeriesVisibility, Converter={StaticResource bvc}}" MaxWidth="1000" ColumnPadding="0"/>
<lvc:ColumnSeries Title="John" Values="7,2,8,3,9" Visibility="{Binding JohnSeriesVisibility, Converter={StaticResource bvc}}" MaxWidth="1000" ColumnPadding="0"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis Labels="January, February, March, April, May">
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,61 @@
using System.ComponentModel;
using System.Windows.Controls;
namespace Wpf.CartesianChart.DynamicVisibility
{
public partial class DynamicVisibilityExample : UserControl, INotifyPropertyChanged
{
private bool _mariaSeriesVisibility;
private bool _charlesSeriesVisibility;
private bool _johnSeriesVisibility;
public DynamicVisibilityExample()
{
InitializeComponent();
MariaSeriesVisibility = true;
CharlesSeriesVisibility = true;
JohnSeriesVisibility = false;
DataContext = this;
}
public bool MariaSeriesVisibility
{
get { return _mariaSeriesVisibility; }
set
{
_mariaSeriesVisibility = value;
OnPropertyChanged("MariaSeriesVisibility");
}
}
public bool CharlesSeriesVisibility
{
get { return _charlesSeriesVisibility; }
set
{
_charlesSeriesVisibility = value;
OnPropertyChanged("CharlesSeriesVisibility");
}
}
public bool JohnSeriesVisibility
{
get { return _johnSeriesVisibility; }
set
{
_johnSeriesVisibility = value;
OnPropertyChanged("JohnSeriesVisibility");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,64 @@
<UserControl x:Class="Wpf.CartesianChart.Energy_Predictions.EnergyPredictionExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Energy_Predictions"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="6"
Background="#ECECEC" d:DataContext="{d:DesignInstance local:EnergyPredictionExample}">
<Grid Margin="20" Width="620">
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" Opacity=".2" ShadowDepth="1"/>
</Grid.Effect>
<Grid.Resources>
<local:OpacityConverter x:Key="OpacityConverter"></local:OpacityConverter>
<local:ReverseConverter x:Key="ReverseConverter"></local:ReverseConverter>
</Grid.Resources>
<Border CornerRadius="5" Background="White">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontSize="40" Foreground="#404040" Margin="20, 10">Energy Consumption</TextBlock>
<Canvas Grid.Row="1" Name="Canvas" Margin="-4, 0, 0, 20">
<ListBox Name="ListBox" ItemsSource="{Binding Series, Converter={StaticResource ReverseConverter}}" PreviewMouseDown="ListBox_OnPreviewMouseDown"
Panel.ZIndex="1" Canvas.Left="60" Canvas.Top="20" BorderThickness="0" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding (lvc:LineSeries.Title)}"
Foreground="{Binding (lvc:LineSeries.Fill)}"
Opacity="{Binding (lvc:LineSeries.Visibility), Converter={StaticResource OpacityConverter}}"
FontSize="22"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<lvc:CartesianChart Height="{Binding ElementName=Canvas, Path=ActualHeight}" Width="{Binding ElementName=Canvas, Path=ActualWidth}"
Series="{Binding Series}" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.AxisX>
<lvc:Axis IsEnabled="False" ShowLabels="False"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis IsMerged="True" FontSize="14"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Canvas>
</Grid>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,59 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Energy_Predictions
{
/// <summary>
/// Interaction logic for EnergyPredictionExample.xaml
/// </summary>
public partial class EnergyPredictionExample : UserControl
{
public EnergyPredictionExample()
{
InitializeComponent();
Series = new SeriesCollection
{
new StackedAreaSeries
{
Values = new ChartValues<double> {20, 30, 35, 45, 65, 85},
Title = "Electricity"
},
new StackedAreaSeries
{
Values = new ChartValues<double> {10, 12, 18, 20, 38, 40},
Title = "Water"
},
new StackedAreaSeries
{
Values = new ChartValues<double> {5, 8, 12, 15, 22, 25},
Title = "Solar"
},
new StackedAreaSeries
{
Values = new ChartValues<double> {10, 12, 18, 20, 38, 40},
Title = "Gas"
}
};
DataContext = this;
}
public SeriesCollection Series { get; set; }
private void ListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var item = ItemsControl.ContainerFromElement(ListBox, (DependencyObject)e.OriginalSource) as ListBoxItem;
if (item == null) return;
var series = (StackedAreaSeries) item.Content;
series.Visibility = series.Visibility == Visibility.Visible
? Visibility.Hidden
: Visibility.Visible;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Wpf.CartesianChart.Energy_Predictions
{
public class OpacityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (Visibility) value == Visibility.Visible
? 1d
: .2d;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using LiveCharts;
namespace Wpf.CartesianChart.Energy_Predictions
{
public class ReverseConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((SeriesCollection) value).Reverse();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Windows.Input;
namespace Wpf.CartesianChart.Events
{
public class MyCommand<T> : ICommand where T : class
{
public Predicate<T> CanExecuteDelegate { get; set; }
public Action<T> ExecuteDelegate { get; set; }
public bool CanExecute(object parameter)
{
return CanExecuteDelegate == null || CanExecuteDelegate((T) parameter);
}
public void Execute(object parameter)
{
if (ExecuteDelegate != null) ExecuteDelegate((T) parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
}

View File

@@ -0,0 +1,38 @@
<UserControl x:Class="Wpf.CartesianChart.Events.EventsExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock>
<TextBlock >Mouse at: </TextBlock>
<TextBlock Name="X"></TextBlock>
<TextBlock >, </TextBlock>
<TextBlock Name="Y"></TextBlock>
</TextBlock>
<lvc:CartesianChart Grid.Row="1" Name="Chart" Zoom="Xy"
MouseMove="ChartMouseMove"
DataClick="ChartOnDataClick"
DataHover="Chart_OnDataHover"
UpdaterTick="ChartOnUpdaterTick"
DataClickCommand="{Binding DataClickCommand}"
DataHoverCommand="{Binding DataHoverCommand}"
UpdaterTickCommand="{Binding UpdaterTickCommand}">
<lvc:CartesianChart.AxisX>
<lvc:Axis RangeChanged="Axis_OnRangeChanged"
RangeChangedCommand="{Binding RangeChangedCommand}"/>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="4,6,5,3,5" Fill="Transparent" StrokeThickness="4"
Panel.ZIndex="2" PointGeometrySize="25"/>
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,49 @@
using System;
using System.Windows.Controls;
using System.Windows.Input;
using LiveCharts;
using LiveCharts.Events;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Events
{
public partial class EventsExample : UserControl
{
public EventsExample()
{
InitializeComponent();
DataContext = new ViewModel();
}
private void ChartOnDataClick(object sender, ChartPoint p)
{
var asPixels = Chart.ConvertToPixels(p.AsPoint());
Console.WriteLine("[EVENT] You clicked (" + p.X + ", " + p.Y + ") in pixels (" +
asPixels.X + ", " + asPixels.Y + ")");
}
private void Chart_OnDataHover(object sender, ChartPoint p)
{
Console.WriteLine("[EVENT] you hovered over " + p.X + ", " + p.Y);
}
private void ChartOnUpdaterTick(object sender)
{
Console.WriteLine("[EVENT] chart was updated");
}
private void Axis_OnRangeChanged(RangeChangedEventArgs eventargs)
{
Console.WriteLine("[EVENT] axis range changed");
}
private void ChartMouseMove(object sender, MouseEventArgs e)
{
var point = Chart.ConvertToChartValues(e.GetPosition(Chart));
X.Text = point.X.ToString("N");
Y.Text = point.Y.ToString("N");
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using LiveCharts;
using LiveCharts.Events;
namespace Wpf.CartesianChart.Events
{
public class ViewModel
{
public ViewModel()
{
DataClickCommand = new MyCommand<ChartPoint>
{
ExecuteDelegate = p => Console.WriteLine(
"[COMMAND] you clicked " + p.X + ", " + p.Y)
};
DataHoverCommand = new MyCommand<ChartPoint>
{
ExecuteDelegate = p => Console.WriteLine(
"[COMMAND] you hovered over " + p.X + ", " + p.Y)
};
UpdaterTickCommand = new MyCommand<LiveCharts.Wpf.CartesianChart>
{
ExecuteDelegate = c => Console.WriteLine("[COMMAND] Chart was updated!")
};
RangeChangedCommand = new MyCommand<RangeChangedEventArgs>
{
ExecuteDelegate = e => Console.WriteLine("[COMMAND] Axis range changed")
};
}
public MyCommand<ChartPoint> DataHoverCommand { get; set; }
public MyCommand<ChartPoint> DataClickCommand { get; set; }
public MyCommand<LiveCharts.Wpf.CartesianChart> UpdaterTickCommand { get; set; }
public MyCommand<RangeChangedEventArgs> RangeChangedCommand { get; set; }
}
}

View File

@@ -0,0 +1,26 @@
<UserControl x:Class="Wpf.CartesianChart.Financial.CandleStickExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Financial"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0">
<Bold>New in 0.7.0</Bold> Financial series
</TextBlock>
<Button Grid.Row="1" Click="UpdateAllOnClick">Update Open and Close</Button>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}">
<lvc:CartesianChart.AxisX>
<lvc:Axis Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,108 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Financial
{
/// <summary>
/// Interaction logic for CandleStickExample.xaml
/// </summary>
public partial class CandleStickExample : UserControl, INotifyPropertyChanged
{
private string[] _labels;
public CandleStickExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new CandleSeries
{
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 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 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 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 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)
}
}
};
//based on https://github.com/beto-rodriguez/Live-Charts/issues/166
//The Ohcl point X property is zero based indexed.
//this means the first point is 0, second 1, third 2.... and so on
//then you can use the Axis.Labels properties to map the chart X with a label in the array.
//for more info see (mapped labels section)
//http://lvcharts.net/#/examples/v1/labels-wpf?path=WPF-Components-Labels
Labels = new[]
{
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;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels
{
get { return _labels; }
set
{
_labels = value;
OnPropertyChanged("Labels");
}
}
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var point in SeriesCollection[0].Values.Cast<OhlcPoint>())
{
point.Open = r.Next((int)point.Low, (int)point.High);
point.Close = r.Next((int)point.Low, (int)point.High);
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,24 @@
<UserControl x:Class="Wpf.CartesianChart.Financial.OhclExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:financial="clr-namespace:Wpf.CartesianChart.Financial"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance financial:OhclExample }">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="1" Click="UpdateAllOnClick">Update Open and Close</Button>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}">
<lvc:CartesianChart.AxisX>
<lvc:Axis Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,91 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Wpf.Annotations;
namespace Wpf.CartesianChart.Financial
{
public partial class OhclExample : UserControl, INotifyPropertyChanged
{
private string[] _labels;
public OhclExample()
{
InitializeComponent();
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
}
};
//based on https://github.com/beto-rodriguez/Live-Charts/issues/166
//The Ohcl point X property is zero based indexed.
//this means the first point is 0, second 1, third 2.... and so on
//then you can use the Axis.Labels properties to map the chart X with a label in the array.
//for more info see (mapped labels section)
//http://lvcharts.net/#/examples/v1/labels-wpf?path=WPF-Components-Labels
Labels = new []
{
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;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels
{
get { return _labels; }
set
{
_labels = value;
OnPropertyChanged("Labels");
}
}
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var point in SeriesCollection[0].Values.Cast<OhlcPoint>())
{
point.Open = r.Next((int) point.Low, (int) point.High);
point.Close = r.Next((int) point.Low, (int) point.High);
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,32 @@
<UserControl x:Class="Wpf.CartesianChart.FullyResponsive.FullyResponsiveExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:fullyResponsive="clr-namespace:Wpf.CartesianChart.FullyResponsive"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance fullyResponsive:FullyResponsiveExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap">
Fully Responsive
</TextBlock>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="0 0 10 0">Points</TextBlock>
<Button Click="AddPointOnClick">+</Button>
<Button Click="InsertPointOnClick">/</Button>
<Button Click="RemovePointOnClick">-</Button>
<Button Click="MoveAllOnClick">MoveAll</Button>
<TextBlock Margin="0 0 10 0" VerticalAlignment="Center">Series</TextBlock>
<Button Click="AddSeriesOnClick">+</Button>
<Button Click="RemoveSeriesOnClick">-</Button>
</StackPanel>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}" LegendLocation="Right"></lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,100 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.FullyResponsive
{
public partial class FullyResponsiveExample : UserControl
{
public FullyResponsiveExample()
{
InitializeComponent();
MyValues = new ChartValues<ObservableValue>
{
new ObservableValue(5),
new ObservableValue(7),
new ObservableValue(8),
new ObservableValue(3)
};
var lineSeries = new LineSeries
{
Values = MyValues,
StrokeThickness = 4,
Fill = Brushes.Transparent,
PointGeometrySize = 0,
DataLabels = true
};
SeriesCollection = new SeriesCollection {lineSeries};
DataContext = this;
}
public ChartValues<ObservableValue> MyValues { get; set; }
public SeriesCollection SeriesCollection { get; set; }
private void AddPointOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
MyValues.Add(new ObservableValue(r.Next(-20, 20)));
}
private void InsertPointOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
if (MyValues.Count > 3)
MyValues.Insert(2, new ObservableValue(r.Next(-20, 20)));
}
private void RemovePointOnClick(object sender, RoutedEventArgs e)
{
MyValues.RemoveAt(0);
}
private void AddSeriesOnClick(object sender, RoutedEventArgs e)
{
//Yes it also listens for series changes
var r = new Random();
var c = SeriesCollection[0].Values.Count;
var val = new ChartValues<ObservableValue>();
for (int i = 0; i < c; i++)
{
val.Add(new ObservableValue(r.Next(-20, 20)));
}
SeriesCollection.Add(new LineSeries
{
Values = val,
StrokeThickness = 4,
Fill = Brushes.Transparent,
PointGeometrySize = 0
});
}
private void RemoveSeriesOnClick(object sender, RoutedEventArgs e)
{
var s = SeriesCollection.Where(x => x.Values != MyValues).ToList();
if (s.Count > 0) SeriesCollection.RemoveAt(1);
}
private void MoveAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var observable in MyValues)
{
observable.Value = r.Next(-20, 20);
}
}
}
}

View File

@@ -0,0 +1,90 @@
<UserControl x:Class="Wpf.CartesianChart.Funnel_Chart.FunnelExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Funnel_Chart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="600">
<Grid Background="#14144B">
<!-- Credit https://dribbble.com/shots/2673159-Funnel-UI-concept-->
<!-- Icons http://www.flaticon.com/authors/madebyoliver -->
<Grid.Resources>
<Style TargetType="lvc:LineSeries">
<Setter Property="PointGeometry" Value="{x:Null}"/>
<Setter Property="AreaLimit" Value="0"/>
<Setter Property="StrokeThickness" Value="0" />
<Setter Property="Fill" Value="#216AFE"></Setter>
</Style>
<Style TargetType="lvc:Axis">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="ShowLabels" Value="False"></Setter>
</Style>
</Grid.Resources>
<lvc:CartesianChart Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="100, 85, 50, 35, 5, 3"/>
<lvc:LineSeries Values="-100, -85, -50, -35, -5, 3"/>
<!--Shadows-->
<lvc:LineSeries Values="110, 94, 60, 40, 10, 10" Fill="#222C78" Panel.ZIndex="-1"/>
<lvc:LineSeries Values="-110, -94, -60, -40, -10, -10" Fill="#222C78" Panel.ZIndex="-1"/>
<lvc:LineSeries Values="120, 104, 70, 50, 15, 15" Fill="#141859" Panel.ZIndex="-2"/>
<lvc:LineSeries Values="-120, -104, -70, -50, -15, -15" Fill="#141859" Panel.ZIndex="-2"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis>
<lvc:Axis.Sections>
<lvc:AxisSection Value="1.5" Stroke="#25FFFFFF" StrokeThickness="5" Panel.ZIndex="1" />
<lvc:AxisSection Value="3.5" Stroke="#25FFFFFF" StrokeThickness="5" Panel.ZIndex="1" />
</lvc:Axis.Sections>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.VisualElements>
<lvc:VisualElement X="0.75" Y="120" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<StackPanel Orientation="Vertical">
<Image Source="resources/user.png"></Image>
<TextBlock Foreground="White" FontSize="16" FontWeight="Bold">LOADED THE AD</TextBlock>
</StackPanel>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="0.75" Y="0" VerticalAlignment="Center" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<TextBlock Foreground="White" FontSize="40">100 %</TextBlock>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="2.5" Y="120" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<StackPanel Orientation="Vertical">
<Image Source="resources/view.png"></Image>
<TextBlock Foreground="White" FontSize="16" FontWeight="Bold">SAW THE AD</TextBlock>
</StackPanel>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="2.5" Y="0" VerticalAlignment="Center" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<TextBlock Foreground="White" FontSize="40">50 %</TextBlock>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="4.25" Y="120" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<StackPanel Orientation="Vertical">
<Image Source="resources/fingerprint.png"></Image>
<TextBlock Foreground="White" FontSize="16" FontWeight="Bold">INTERACTED</TextBlock>
</StackPanel>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="4.25" Y="0" VerticalAlignment="Center" HorizontalAlignment="Center">
<lvc:VisualElement.UIElement>
<TextBlock Foreground="White" FontSize="40">5 %</TextBlock>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
</lvc:CartesianChart.VisualElements>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace Wpf.CartesianChart.Funnel_Chart
{
/// <summary>
/// Interaction logic for FunnelExample.xaml
/// </summary>
public partial class FunnelExample : UserControl
{
public FunnelExample()
{
InitializeComponent();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

View File

@@ -0,0 +1,30 @@
<UserControl x:Class="Wpf.CartesianChart.GanttChart.GanttExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.GanttChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Click="ResetZoomOnClick">Reset zoom</Button>
<TextBlock Margin="10" TextWrapping="Wrap">Use your mouse wheel to zoom in/out, click hold and drag for panning</TextBlock>
</StackPanel>
<lvc:CartesianChart Grid.Row="1" Series="{Binding Series}" Zoom="X">
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Formatter}"
MinValue="{Binding From, Mode=TwoWay}"
MaxValue="{Binding To, Mode=TwoWay}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.GanttChart
{
/// <summary>
/// Interaction logic for GanttExample.xaml
/// </summary>
public partial class GanttExample : UserControl, INotifyPropertyChanged
{
private double _from;
private double _to;
private readonly ChartValues<GanttPoint> _values;
public GanttExample()
{
InitializeComponent();
var now = DateTime.Now;
_values = new ChartValues<GanttPoint>
{
new GanttPoint(now.Ticks, now.AddDays(2).Ticks),
new GanttPoint(now.AddDays(1).Ticks, now.AddDays(3).Ticks),
new GanttPoint(now.AddDays(3).Ticks, now.AddDays(5).Ticks),
new GanttPoint(now.AddDays(5).Ticks, now.AddDays(8).Ticks),
new GanttPoint(now.AddDays(6).Ticks, now.AddDays(10).Ticks),
new GanttPoint(now.AddDays(7).Ticks, now.AddDays(14).Ticks),
new GanttPoint(now.AddDays(9).Ticks, now.AddDays(12).Ticks),
new GanttPoint(now.AddDays(9).Ticks, now.AddDays(14).Ticks),
new GanttPoint(now.AddDays(10).Ticks, now.AddDays(11).Ticks),
new GanttPoint(now.AddDays(12).Ticks, now.AddDays(16).Ticks),
new GanttPoint(now.AddDays(15).Ticks, now.AddDays(17).Ticks),
new GanttPoint(now.AddDays(18).Ticks, now.AddDays(19).Ticks)
};
Series = new SeriesCollection
{
new RowSeries
{
Values = _values,
DataLabels = true
}
};
Formatter = value => new DateTime((long) value).ToString("dd MMM");
var labels = new List<string>();
for (var i = 0; i < 12; i++)
labels.Add("Task " + i);
Labels = labels.ToArray();
ResetZoomOnClick(null, null);
DataContext = this;
}
public SeriesCollection Series { get; set; }
public Func<double, string> Formatter { get; set; }
public string[] Labels { get; set; }
public double From
{
get { return _from; }
set
{
_from = value;
OnPropertyChanged("From");
}
}
public double To
{
get { return _to; }
set
{
_to = value;
OnPropertyChanged("To");
}
}
private void ResetZoomOnClick(object sender, RoutedEventArgs e)
{
From = _values.First().StartPoint;
To = _values.Last().EndPoint;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,47 @@
<UserControl x:Class="Wpf.CartesianChart.HeatChart.HeatSeriesExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:heatChart="clr-namespace:Wpf.CartesianChart.HeatChart"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance heatChart:HeatSeriesExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Click="ButtonBase_OnClick" Margin="10">Randomize</Button>
<lvc:CartesianChart Grid.Row="1" DataTooltip="{x:Null}">
<lvc:CartesianChart.Series>
<lvc:HeatSeries Values="{Binding Values}" DataLabels="True">
<!--
The GradientStopCollection is optional to define a custom gradient
If this property is not specified, LiveCharts will set a gradient
-->
<lvc:HeatSeries.GradientStopCollection>
<GradientStop Offset="0" Color="#99FFFF00"></GradientStop>
<GradientStop Offset=".25" Color="#FFFFFF00"></GradientStop>
<GradientStop Offset=".50" Color="#990000FF"></GradientStop>
<GradientStop Offset=".75" Color="#FF0000FF"></GradientStop>
<GradientStop Offset="1" Color="#50505050"></GradientStop>
</lvc:HeatSeries.GradientStopCollection>
</lvc:HeatSeries>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX >
<lvc:Axis Labels="{Binding SalesMan}" LabelsRotation="-15">
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Labels="{Binding Days}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,104 @@
using System;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
namespace Wpf.CartesianChart.HeatChart
{
public partial class HeatSeriesExample : UserControl
{
public HeatSeriesExample()
{
InitializeComponent();
var r = new Random();
Values = new ChartValues<HeatPoint>
{
//X means sales man
//Y is the day
//"Jeremy Swanson"
new HeatPoint(0, 0, r.Next(0, 10)),
new HeatPoint(0, 1, r.Next(0, 10)),
new HeatPoint(0, 2, r.Next(0, 10)),
new HeatPoint(0, 3, r.Next(0, 10)),
new HeatPoint(0, 4, r.Next(0, 10)),
new HeatPoint(0, 5, r.Next(0, 10)),
new HeatPoint(0, 6, r.Next(0, 10)),
//"Lorena Hoffman"
new HeatPoint(1, 0, r.Next(0, 10)),
new HeatPoint(1, 1, r.Next(0, 10)),
new HeatPoint(1, 2, r.Next(0, 10)),
new HeatPoint(1, 3, r.Next(0, 10)),
new HeatPoint(1, 4, r.Next(0, 10)),
new HeatPoint(1, 5, r.Next(0, 10)),
new HeatPoint(1, 6, r.Next(0, 10)),
//"Robyn Williamson"
new HeatPoint(2, 0, r.Next(0, 10)),
new HeatPoint(2, 1, r.Next(0, 10)),
new HeatPoint(2, 2, r.Next(0, 10)),
new HeatPoint(2, 3, r.Next(0, 10)),
new HeatPoint(2, 4, r.Next(0, 10)),
new HeatPoint(2, 5, r.Next(0, 10)),
new HeatPoint(2, 6, r.Next(0, 10)),
//"Carole Haynes"
new HeatPoint(3, 0, r.Next(0, 10)),
new HeatPoint(3, 1, r.Next(0, 10)),
new HeatPoint(3, 2, r.Next(0, 10)),
new HeatPoint(3, 3, r.Next(0, 10)),
new HeatPoint(3, 4, r.Next(0, 10)),
new HeatPoint(3, 5, r.Next(0, 10)),
new HeatPoint(3, 6, r.Next(0, 10)),
//"Essie Nelson"
new HeatPoint(4, 0, r.Next(0, 10)),
new HeatPoint(4, 1, r.Next(0, 10)),
new HeatPoint(4, 2, r.Next(0, 10)),
new HeatPoint(4, 3, r.Next(0, 10)),
new HeatPoint(4, 4, r.Next(0, 10)),
new HeatPoint(4, 5, r.Next(0, 10)),
new HeatPoint(4, 6, r.Next(0, 10))
};
Days = new[]
{
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
SalesMan = new[]
{
"Jeremy Swanson",
"Lorena Hoffman",
"Robyn Williamson",
"Carole Haynes",
"Essie Nelson"
};
DataContext = this;
}
public ChartValues<HeatPoint> Values { get; set; }
public string[] Days { get; set; }
public string[] SalesMan { get; set; }
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var chartValue in Values)
{
chartValue.Weight = r.Next(0, 10);
}
}
}
}

View File

@@ -0,0 +1,26 @@
<UserControl x:Class="Wpf.CartesianChart.InLineSyntaxTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:liveCharts="clr-namespace:LiveCharts;assembly=LiveCharts"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock>This chart is totally built with XAML.</TextBlock>
<lc:CartesianChart Grid.Row="1">
<lc:CartesianChart.Series>
<lc:LineSeries Values="1,2,3,5" />
<lc:LineSeries Values="4,6,2,5" />
</lc:CartesianChart.Series>
<lc:CartesianChart.AxisX>
<lc:Axis Labels="Jan, Feb, Mar, Apr, May, Jun, Ago, Sep, Oct"/>
</lc:CartesianChart.AxisX>
</lc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 Wpf.CartesianChart
{
/// <summary>
/// Interaction logic for InLineSintaxTest.xaml
/// </summary>
public partial class InLineSyntaxTest : UserControl
{
public InLineSyntaxTest()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,31 @@
<UserControl x:Class="Wpf.CartesianChart.Inverted_Series.InvertedExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Inverted_Series"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:RowSeries Values="{Binding Values2}" Panel.ZIndex="1"></lvc:RowSeries>
<lvc:VerticalLineSeries Values="{Binding Values1}" Panel.ZIndex="0"></lvc:VerticalLineSeries>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis>
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis MinValue="0"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,23 @@
using System.Windows.Controls;
using LiveCharts;
namespace Wpf.CartesianChart.Inverted_Series
{
public partial class InvertedExample : UserControl
{
public InvertedExample()
{
InitializeComponent();
Values1 = new ChartValues<double> {3, 5, 2, 6, 2, 7, 1};
Values2 = new ChartValues<double> {6, 2, 6, 3, 2, 7, 2};
DataContext = this;
}
public ChartValues<double> Values1 { get; set; }
public ChartValues<double> Values2 { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Wpf.CartesianChart.Irregular_Intervals.IrregularIntervalsExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,60 @@
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Irregular_Intervals
{
public partial class IrregularIntervalsExample : UserControl
{
public IrregularIntervalsExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<ObservablePoint>
{
new ObservablePoint(0, 10),
new ObservablePoint(4, 7),
new ObservablePoint(5, 3),
new ObservablePoint(7, 6),
new ObservablePoint(10, 8)
},
PointGeometrySize = 15
},
new LineSeries
{
Values = new ChartValues<ObservablePoint>
{
new ObservablePoint(0, 2),
new ObservablePoint(2, 5),
new ObservablePoint(3, 6),
new ObservablePoint(6, 8),
new ObservablePoint(10, 5)
},
PointGeometrySize = 15
},
new LineSeries
{
Values = new ChartValues<ObservablePoint>
{
new ObservablePoint(0, 4),
new ObservablePoint(5, 5),
new ObservablePoint(7, 7),
new ObservablePoint(9, 10),
new ObservablePoint(10, 9)
},
PointGeometrySize = 15
}
};
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
}
}

View File

@@ -0,0 +1,35 @@
<UserControl x:Class="Wpf.CartesianChart.Labels.LabelsExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:labels="clr-namespace:Wpf.CartesianChart.Labels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance labels:LabelsExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock>Labels</TextBlock>
<Button Grid.Row="1" Height="30" Click="UpdateAllOnClick">
Move All
</Button>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}"
DataClick="Chart_OnDataClick">
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelsRotation="20" Labels="{Binding Labels}" Position="LeftBottom" >
<lvc:Axis.Separator >
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Items" LabelFormatter="{Binding Formatter}" Position="RightTop"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,82 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Labels
{
/// <summary>
/// Interaction logic for BarExample.xaml
/// </summary>
public partial class LabelsExample : UserControl
{
public LabelsExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new ColumnSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(4),
new ObservableValue(2),
new ObservableValue(8),
new ObservableValue(2),
new ObservableValue(3),
new ObservableValue(0),
new ObservableValue(1),
},
DataLabels = true,
LabelPoint = point => point.X + "K ," + point.Y
}
};
Labels = new[]
{
"Shea Ferriera",
"Maurita Powel",
"Scottie Brogdon",
"Teresa Kerman",
"Nell Venuti",
"Anibal Brothers",
"Anderson Dillman"
};
Formatter = value => value + ".00K items";
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var series in SeriesCollection)
{
foreach (var observable in series.Values.Cast<ObservableValue>())
{
observable.Value = r.Next(0, 10);
}
}
}
private void Chart_OnDataClick(object sender, ChartPoint point)
{
//point instance contains many useful information...
//sender is the shape that called the event.
MessageBox.Show("You clicked " + point.X + ", " + point.Y);
}
}
}

View File

@@ -0,0 +1,36 @@
<UserControl x:Class="Wpf.CartesianChart.Labels.LabelsHorizontalExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Labels"
xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock>Labels</TextBlock>
<Button Grid.Row="1" Height="30" Click="UpdateAllOnClick">
Move All
</Button>
<wpf:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}">
<wpf:CartesianChart.DataTooltip>
<wpf:DefaultTooltip SelectionMode="SharedYValues"></wpf:DefaultTooltip>
</wpf:CartesianChart.DataTooltip>
<wpf:CartesianChart.AxisX>
<wpf:Axis Title="Sold Items" LabelFormatter="{Binding Formatter}"></wpf:Axis>
</wpf:CartesianChart.AxisX>
<wpf:CartesianChart.AxisY>
<wpf:Axis Labels="{Binding Labels}" LabelsRotation="65">
<wpf:Axis.Separator >
<wpf:Separator Step="1"></wpf:Separator>
</wpf:Axis.Separator>
</wpf:Axis>
</wpf:CartesianChart.AxisY>
</wpf:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,75 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Labels
{
/// <summary>
/// Interaction logic for LabelsHorizontalExample.xaml
/// </summary>
public partial class LabelsHorizontalExample : UserControl
{
public LabelsHorizontalExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new RowSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(4),
new ObservableValue(2),
new ObservableValue(8),
new ObservableValue(2),
new ObservableValue(3),
new ObservableValue(0),
new ObservableValue(1),
},
DataLabels = true,
LabelPoint = point => point.X + "K ," + point.Y
}
};
Labels = new[]
{
"Shea Ferriera",
"Maurita Powel",
"Scottie Brogdon",
"Teresa Kerman",
"Nell Venuti",
"Anibal Brothers",
"Anderson Dillman"
};
Formatter = value => value + ".00K items";
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var series in SeriesCollection)
{
foreach (var observable in series.Values.Cast<ObservableValue>())
{
observable.Value = r.Next(0, 10);
}
}
}
}
}

View File

@@ -0,0 +1,26 @@
<UserControl x:Class="Wpf.CartesianChart.LineExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:LineExample }">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<lvc:CartesianChart Grid.Row="2">
<lvc:CartesianChart.Series>
<lvc:VerticalLineSeries Values="{Binding Values}" DataLabels="True" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.DataTooltip>
<!--The Selection mode property should be done automatically in future versions-->
<lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,46 @@
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;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart
{
/// <summary>
/// Interaction logic for LineExample.xaml
/// </summary>
public partial class LineExample : UserControl
{
public LineExample()
{
InitializeComponent();
Values = Values = new ChartValues<float>
{
3,
4,
6,
3,
2,
6
};
DataContext = this;
}
public ChartValues<float> Values { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
namespace Wpf.CartesianChart.Linq
{
public class City
{
public Guid Id { get; set; }
public string Name { get; set; }
public double Population { get; set; }
public double Area { get; set; }
public string Country { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace Wpf.CartesianChart.Linq
{
public static class DataBase
{
static DataBase()
{
var reader = new StreamReader(File.OpenRead(@"cities.csv"));
var read = new List<City>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line != null)
{
var values = line.Split(',');
read.Add(new City
{
Name = values[0],
Population = double.Parse(values[1], CultureInfo.InvariantCulture),
Area = double.Parse(values[2], CultureInfo.InvariantCulture),
Country = values[3]
});
}
}
Cities = read.ToArray();
}
public static City[] Cities { get; private set; }
}
}

View File

@@ -0,0 +1,39 @@
<UserControl x:Class="Wpf.CartesianChart.Linq.LinqExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Linq"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
d:DataContext="{d:DesignInstance local:LinqExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="10 0">Search</TextBlock>
<TextBox Name="Query" VerticalContentAlignment="Center" Width="100" Height="30"
TextChanged="TextBoxBase_OnTextChanged"></TextBox>
</StackPanel>
<lvc:CartesianChart Grid.Row="1" >
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Title="2016 Population by City"
Values="{Binding Results}"
Configuration="{Binding Mapper}"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelsRotation="-20" Labels="{Binding Labels}" DisableAnimations="True">
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis LabelFormatter="{Binding MillionFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Helpers;
namespace Wpf.CartesianChart.Linq
{
public partial class LinqExample : UserControl
{
public LinqExample()
{
InitializeComponent();
//lets configure the chart to plot cities
Mapper = Mappers.Xy<City>()
.X((city, index) => index)
.Y(city => city.Population);
//lets take the first 15 records by default;
var records = DataBase.Cities.OrderByDescending(x => x.Population).Take(15).ToArray();
Results = records.AsChartValues();
Labels = new ObservableCollection<string>(records.Select(x => x.Name));
MillionFormatter = value => (value/1000000).ToString("N") + "M";
DataContext = this;
}
public ChartValues<City> Results { get; set; }
public ObservableCollection<string> Labels { get; set; }
public Func<double, string> MillionFormatter { get; set; }
public object Mapper { get; set; }
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
{
var q = (Query.Text ?? string.Empty).ToUpper();
var records = DataBase.Cities
.Where(x => x.Name.ToUpper().Contains(q) || x.Country.ToUpper().Contains(q))
.OrderByDescending(x => x.Population)
.Take(15)
.ToArray();
Results.Clear();
Results.AddRange(records);
Labels.Clear();
foreach (var record in records) Labels.Add(record.Name);
}
}
}

View File

@@ -0,0 +1,27 @@
<UserControl x:Class="Wpf.CartesianChart.LogarithmScale.LogarithmScaleExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.LogarithmScale"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}">
<lvc:CartesianChart.Resources>
<Style TargetType="lvc:Separator">
<Setter Property="Stroke" Value="LightGray"></Setter>
</Style>
</lvc:CartesianChart.Resources>
<lvc:CartesianChart.AxisX>
<lvc:LogarithmicAxis LabelFormatter="{Binding Formatter}"
Base="{Binding Base}" >
<lvc:LogarithmicAxis.Separator>
<lvc:Separator StrokeThickness="1" IsEnabled="True"></lvc:Separator>
</lvc:LogarithmicAxis.Separator>
</lvc:LogarithmicAxis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,50 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.LogarithmScale
{
public partial class LogarithmScaleExample : UserControl
{
public LogarithmScaleExample()
{
InitializeComponent();
Base = 10;
var mapper = Mappers.Xy<ObservablePoint>()
.X(point => Math.Log(point.X, Base)) //a 10 base log scale in the X axis
.Y(point => point.Y);
SeriesCollection = new SeriesCollection(mapper)
{
new LineSeries
{
Values = new ChartValues<ObservablePoint>
{
new ObservablePoint(1, 5),
new ObservablePoint(10, 6),
new ObservablePoint(100, 4),
new ObservablePoint(1000, 2),
new ObservablePoint(10000, 8),
new ObservablePoint(100000, 2),
new ObservablePoint(1000000, 9),
new ObservablePoint(10000000, 8)
}
}
};
Formatter = value => Math.Pow(Base, value).ToString("N");
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public Func<double, string> Formatter { get; set; }
public double Base { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
<UserControl x:Class="Wpf.CartesianChart.ManualZAndP.ManualZAndPExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.ManualZAndP"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Click="PrevOnClick">Prev</Button>
<Button Click="NextOnClick">Next</Button>
</StackPanel>
<Button Grid.Row="1" Click="ManualZoom" HorizontalAlignment="Left">Zoom to 5 &gt; x &lt; 10</Button>
<lvc:CartesianChart Grid.Row="2">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding Values}"></lvc:LineSeries>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis MinValue="{Binding From}" MaxValue="{Binding To}"
Separator="{x:Static lvc:DefaultAxes.CleanSeparator}">
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,84 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using Wpf.Annotations;
namespace Wpf.CartesianChart.ManualZAndP
{
public partial class ManualZAndPExample : UserControl, INotifyPropertyChanged
{
private double _to;
private double _from;
public ManualZAndPExample()
{
InitializeComponent();
Values = new ChartValues<double>();
var r = new Random();
for (var i = 0; i < 100; i++)
{
Values.Add(r.Next(0, 10));
}
//In this case we are paginating the data only showing the first 25 records
//clicking the buttons previous and next changes the page
From = 0;
To = 25;
DataContext = this;
}
public ChartValues<double> Values { get; set; }
public double From
{
get { return _from; }
set
{
_from = value;
OnPropertyChanged("From");
}
}
public double To
{
get { return _to; }
set
{
_to = value;
OnPropertyChanged("To");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void NextOnClick(object sender, RoutedEventArgs e)
{
From += 25;
To += 25;
}
private void PrevOnClick(object sender, RoutedEventArgs e)
{
From -= 25;
To -= 25;
}
private void ManualZoom(object sender, RoutedEventArgs e)
{
//you only need to change the axis limits to zoom in/out any axis.
From = 5;
To = 10;
}
}
}

View File

@@ -0,0 +1,144 @@
<UserControl x:Class="Wpf.CartesianChart.MaterialCards.MaterialCards"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.MaterialCards"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="800"
Background="#E9E9E9">
<Grid Height="500" Width="650" >
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Margin="15, -60, 15, 15" MaxHeight="350">
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" Opacity=".2" ShadowDepth="1"/>
</Grid.Effect>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=Border1}" />
</Grid.OpacityMask>
<Grid.Resources>
<Style TargetType="lvc:LineSeries">
<Setter Property="StrokeThickness" Value="3"></Setter>
<Setter Property="Stroke" Value="White"></Setter>
<Setter Property="Fill" Value="#4EFFFFFF"></Setter>
<Setter Property="PointGeometrySize" Value="0"></Setter>
<Setter Property="LineSmoothness" Value="0"></Setter>
</Style>
<Style TargetType="lvc:Axis">
<Setter Property="ShowLabels" Value="False"></Setter>
<Setter Property="IsEnabled" Value="False"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height=".50*"></RowDefinition>
<RowDefinition Height=".5*"></RowDefinition>
</Grid.RowDefinitions>
<Border x:Name="Border1" Grid.Row="0" Grid.RowSpan="4" CornerRadius="5" Background="White" />
<Border Grid.Row="0" Grid.RowSpan="3" Background="#CE2156" ></Border>
<TextBlock Grid.Row="0" TextAlignment="Center" Padding="10, 10, 0, 5" Foreground="White" FontSize="18">
The Current Chart
</TextBlock>
<TextBlock Grid.Row="1" TextAlignment="Center" Foreground="#59FFFFFF" Padding="0,0,0,20">2014.12.25</TextBlock>
<lvc:CartesianChart Grid.Row="2" Margin="0, 0, 0, 0" Series="{Binding LastHourSeries}" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.AxisX>
<!--a small visual improvement, lets hide the first points (x = 0, x=1) to get better animations-->
<lvc:Axis MinValue="2"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Grid.Row="3" VerticalAlignment="Center" Margin="25, 0">
<TextBlock Opacity=".4" FontSize="13">Total electricity Consumption <LineBreak /> of Galaxy SOHO</TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="#303030" FontSize="40" Text="{Binding LastLecture, StringFormat={}{0:N1}}" />
<TextBlock Foreground="#303030" FontSize="18" VerticalAlignment="Bottom" Margin="8, 6">kWh</TextBlock>
</StackPanel>
</StackPanel>
</Grid>
<Grid Grid.Column="1" Margin="15, 20, 15, 15" MaxHeight="350">
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" Opacity=".2" ShadowDepth="1"/>
</Grid.Effect>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=Border2}" />
</Grid.OpacityMask>
<Grid.Resources>
<Style TargetType="lvc:ColumnSeries">
<Setter Property="StrokeThickness" Value="0"></Setter>
<Setter Property="Stroke" Value="White"></Setter>
<Setter Property="Fill" Value="White"></Setter>
<Setter Property="MaxColumnWidth" Value="5"></Setter>
</Style>
<Style TargetType="lvc:Axis">
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="Foreground" Value="#64FFFFFF"></Setter>
<Style.Triggers>
<Trigger Property="AxisOrientation" Value="Y">
<Setter Property="IsMerged" Value="True"></Setter>
<Setter Property="MaxValue" Value="10"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="lvc:Separator">
<Setter Property="StrokeThickness" Value="1"></Setter>
<Setter Property="Stroke" Value="#4BFFFFFF"></Setter>
<Style.Triggers>
<Trigger Property="AxisOrientation" Value="X">
<Setter Property="IsEnabled" Value="False"></Setter>
<Setter Property="Step" Value="1"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height=".50*"></RowDefinition>
<RowDefinition Height=".5*"></RowDefinition>
</Grid.RowDefinitions>
<Border x:Name="Border2" Grid.Row="0" Grid.RowSpan="4" CornerRadius="5" Background="White" />
<Border Grid.Row="0" Grid.RowSpan="3" Background="#EB5A13" ></Border>
<TextBlock Grid.Row="0" TextAlignment="Center" Padding="10, 10, 0, 5" Foreground="White" FontSize="18">
Time Power
</TextBlock>
<TextBlock Grid.Row="1" TextAlignment="Center" Foreground="#59FFFFFF" Padding="0,0,0,20">2014.12.25</TextBlock>
<Button Grid.Row="3" Width="40" Height="40" VerticalAlignment="Top"
HorizontalAlignment="Right" Margin="20, -20" Panel.ZIndex="1"
Click="UpdateOnclick">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" Opacity=".2" ShadowDepth="1"/>
</Grid.Effect>
<Ellipse Stroke="Black" StrokeThickness="0" Fill="#CD2156">
</Ellipse>
<Path Width="20" Height="20" Stretch="Fill" Fill="White" Data="F1 M 58,33.5001L 58,27L 49,19L 40,27.5001L 40,33.5001L 46,28.2097L 46,40.5C 46,46.299 41.299,51 35.5,51C 29.701,51 25,46.299 25,40.5C 25,34.8686 29.4332,30.2727 35,30.0117L 35,24.0074C 26.1186,24.2718 19,31.5546 19,40.5C 19,49.6127 26.3873,57 35.5,57C 44.6127,57 52,49.6127 52,40.5L 52,28.125L 58,33.5001 Z "/>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
<lvc:CartesianChart Name="TimePowerChart" Grid.Row="2" Margin="10, 0, 10, 20" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Values="5,9,8,6,1,5,7,3,6,3"/>
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
<StackPanel Grid.Row="3" VerticalAlignment="Center" Margin="25, 0">
<TextBlock Opacity=".4" FontSize="13">The Last 12 hours average <LineBreak /> Electricity Consumption</TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="#303030" FontSize="40" Text="20.45" />
<TextBlock Foreground="#303030" FontSize="18" VerticalAlignment="Bottom" Margin="8, 6">kWh</TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
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;
using System.Windows.Threading;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Wpf.Annotations;
namespace Wpf.CartesianChart.MaterialCards
{
/// <summary>
/// Interaction logic for MaterialCards.xaml
/// </summary>
public partial class MaterialCards : UserControl, INotifyPropertyChanged
{
private double _lastLecture;
private double _trend;
public MaterialCards()
{
InitializeComponent();
LastHourSeries = new SeriesCollection
{
new LineSeries
{
AreaLimit = -10,
Values = new ChartValues<ObservableValue>
{
new ObservableValue(3),
new ObservableValue(5),
new ObservableValue(6),
new ObservableValue(7),
new ObservableValue(3),
new ObservableValue(4),
new ObservableValue(2),
new ObservableValue(5),
new ObservableValue(8),
new ObservableValue(3),
new ObservableValue(5),
new ObservableValue(6),
new ObservableValue(7),
new ObservableValue(3),
new ObservableValue(4),
new ObservableValue(2),
new ObservableValue(5),
new ObservableValue(8)
}
}
};
_trend = 8;
#if NET40
Task.Factory.StartNew(() =>
{
var r = new Random();
Action action = delegate
{
LastHourSeries[0].Values.Add(new ObservableValue(_trend));
LastHourSeries[0].Values.RemoveAt(0);
SetLecture();
};
while (true)
{
Thread.Sleep(500);
_trend += (r.NextDouble() > 0.3 ? 1 : -1) * r.Next(0, 5);
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, action);
}
});
#endif
#if NET45
Task.Run(() =>
{
var r = new Random();
while (true)
{
Thread.Sleep(500);
_trend += (r.NextDouble() > 0.3 ? 1 : -1)*r.Next(0, 5);
Application.Current.Dispatcher.Invoke(() =>
{
LastHourSeries[0].Values.Add(new ObservableValue(_trend));
LastHourSeries[0].Values.RemoveAt(0);
SetLecture();
});
}
});
#endif
DataContext = this;
}
public SeriesCollection LastHourSeries { get; set; }
public double LastLecture
{
get { return _lastLecture; }
set
{
_lastLecture = value;
OnPropertyChanged("LastLecture");
}
}
private void SetLecture()
{
var target = ((ChartValues<ObservableValue>)LastHourSeries[0].Values).Last().Value;
var step = (target - _lastLecture) / 4;
#if NET40
Task.Factory.StartNew(() =>
{
for (var i = 0; i < 4; i++)
{
Thread.Sleep(100);
LastLecture += step;
}
LastLecture = target;
});
#endif
#if NET45
Task.Run(() =>
{
for (var i = 0; i < 4; i++)
{
Thread.Sleep(100);
LastLecture += step;
}
LastLecture = target;
});
#endif
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private void UpdateOnclick(object sender, RoutedEventArgs e)
{
TimePowerChart.Update(true);
}
}
}

View File

@@ -0,0 +1,13 @@
<UserControl x:Class="Wpf.CartesianChart.Missing_Line_Points.MissingPointsExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding Series}">
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,40 @@
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Missing_Line_Points
{
public partial class MissingPointsExample : UserControl
{
public MissingPointsExample()
{
InitializeComponent();
Series = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<double>
{
4,
5,
7,
8,
double.NaN,
5,
2,
8,
double.NaN,
6,
2
}
}
};
DataContext = this;
}
public SeriesCollection Series { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
<UserControl x:Class="Wpf.CartesianChart.MixingSeries.MixingTypes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:mixingSeries="clr-namespace:Wpf.CartesianChart.MixingSeries"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance mixingSeries:MixingTypes}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap">
Yes you can mix any series supported by a cartesian chart, just add the series and the chart wll handle it, charts are smart enough to scale according to the contained series.
In this case we will only use ObservableClasses, so the chart updates automatically when a property changes, there are already some observable classes defined in thsi library, you
can also build your own
<Hyperlink NavigateUri="http://lvcharts.net/#/examples/v1/iocp-wpf?path=WPF-Observable" RequestNavigate="OnLinkRequest">
here
</Hyperlink>
is an example
</TextBlock>
<Button Grid.Row="1" Margin="7" Click="UpdateAllOnClick">Click me to update all points</Button>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}"
Background="#303030">
<lvc:CartesianChart.AxisY>
<lvc:Axis>
<lvc:Axis.Separator>
<lvc:Separator Stroke="#606060"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,101 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Navigation;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.MixingSeries
{
/// <summary>
/// Interaction logic for MixingSeries.xaml
/// </summary>
public partial class MixingTypes : UserControl
{
public MixingTypes()
{
InitializeComponent();
LineSeries = new LineSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(5),
new ObservableValue(7),
new ObservableValue(2),
new ObservableValue(3)
},
PointForeground = new SolidColorBrush(Color.FromRgb(50,50,50)),
AreaLimit = 0
};
ScatterSeries = new ScatterSeries
{
Values = new ChartValues<ScatterPoint>
{
new ScatterPoint(0, 2, 10),
new ScatterPoint(1, 1, 2),
new ScatterPoint(2, 3, 7),
new ScatterPoint(3, 4, 9)
}
};
ColumnSeries = new ColumnSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(5),
new ObservableValue(7),
new ObservableValue(2),
new ObservableValue(3)
}
};
SeriesCollection = new SeriesCollection
{
LineSeries,
ScatterSeries,
ColumnSeries
};
DataContext = this;
}
public ScatterSeries ScatterSeries { get; set; }
public LineSeries LineSeries { get; set; }
public ColumnSeries ColumnSeries { get; set; }
public SeriesCollection SeriesCollection { get; set; }
private void OnLinkRequest(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var value in LineSeries.Values.Cast<ObservableValue>())
{
value.Value = r.Next(-20, 20);
}
foreach (var value in ColumnSeries.Values.Cast<ObservableValue>())
{
value.Value = r.Next(-20, 20);
}
var i = 0;
foreach (var value in ScatterSeries.Values.Cast<ScatterPoint>())
{
value.X = i;
value.Y = r.Next(-20, 20);
value.Weight = r.Next(-20, 20);
i++;
}
}
}
}

View File

@@ -0,0 +1,45 @@
<UserControl x:Class="Wpf.CartesianChart.MultiAxesChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.Resources>
<Style x:Key="CleanSeparator" TargetType="lvc:Separator">
<Setter Property="IsEnabled" Value="False"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap">
You can create multiple axes, just set the Series.ScalesXAt or Series.ScalesYAt properties, you must also add the axis explicitly.
</TextBlock>
<lvc:CartesianChart Grid.Row="2">
<lvc:CartesianChart.AxisY>
<lvc:Axis Foreground="DodgerBlue" Title="Blue Axis"/>
<lvc:Axis Foreground="IndianRed" Title="Red Axis" Position="RightTop">
<lvc:Axis.Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
<lvc:Axis Foreground="DarkOliveGreen" Title="Green Axis" Position="RightTop">
<lvc:Axis.Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="1,5,3,5,3" ScalesYAt="0"/> <!--Scales at blue axis, Axis[0]-->
<lvc:LineSeries Values="20,30,70,20,10" ScalesYAt="1"/> <!--Scales at red axis, Axis[1]-->
<lvc:LineSeries Values="600,300,200,600,800" ScalesYAt="2"/> <!--Scales at green axis, Axis[2]-->
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 Wpf.CartesianChart
{
/// <summary>
/// Interaction logic for MultiAxisChart.xaml
/// </summary>
public partial class MultiAxesChart : UserControl
{
public MultiAxesChart()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="Wpf.CartesianChart.NegativeStackedRow.NegativeStackedRowExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.NegativeStackedRow"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:NegativeStackedRowExample }">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}">
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Age Range" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="SharedYValues"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,43 @@
using System;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.NegativeStackedRow
{
/// <summary>
/// Interaction logic for NEgativeStackedRowExample.xaml
/// </summary>
public partial class NegativeStackedRowExample : UserControl
{
public NegativeStackedRowExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new StackedRowSeries
{
Title = "Male",
Values = new ChartValues<double> {.5, .7, .8, .8, .6, .2, .6}
},
new StackedRowSeries
{
Title = "Female",
Values = new ChartValues<double> {-.5, -.7, -.8, -.8, -.6, -.2, -.6}
}
};
Labels = new[] {"0-20", "20-35", "35-45", "45-55", "55-65", "65-70", ">70"};
Formatter = value => Math.Abs(value).ToString("P");
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> Formatter { get; set; }
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.PointShapeLine
{
public partial class PointShapeLineExample : UserControl
{
public PointShapeLineExample()
{
InitializeComponent();
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
}
};
Labels = new[] {"Jan", "Feb", "Mar", "Apr", "May"};
YFormatter = value => value.ToString("C");
//modifying the series collection will animate and update the chart
SeriesCollection.Add(new LineSeries
{
Title = "Series 4",
Values = new ChartValues<double> {5, 3, 2, 4},
LineSmoothness = 0, //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
});
//modifying any series values will also animate and update the chart
SeriesCollection[3].Values.Add(5d);
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public string[] Labels { get; set; }
public Func<double, string> YFormatter { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
<UserControl x:Class="Wpf.CartesianChart.PointShapeLine.PointShapeLineExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.BasicLine"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Right" >
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Month" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,25 @@
<UserControl x:Class="Wpf.CartesianChart.PointState.PointStateExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:pointState="clr-namespace:Wpf.CartesianChart.PointState"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance pointState:PointStateExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Click="UpdateDataOnClick">Update Data</Button>
<lvc:CartesianChart Grid.Row="1">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding Values}"
PointGeometrySize="20"
PointForeground="White"
Configuration="{Binding Mapper}"/>
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,60 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Defaults;
namespace Wpf.CartesianChart.PointState
{
/// <summary>
/// Interaction logic for PointStateExample.xaml
/// </summary>
public partial class PointStateExample : UserControl
{
public PointStateExample()
{
InitializeComponent();
var r = new Random();
Values = new ChartValues<ObservableValue>
{
new ObservableValue(r.Next(10, 400)),
new ObservableValue(r.Next(10, 400)),
new ObservableValue(r.Next(10, 400)),
new ObservableValue(r.Next(10, 400)),
new ObservableValue(r.Next(10, 400)),
new ObservableValue(r.Next(10, 400))
};
//Lets define a custom mapper, to set fill and stroke
//according to chart values...
Mapper = Mappers.Xy<ObservableValue>()
.X((item, index) => index)
.Y(item => item.Value)
.Fill(item => item.Value > 200 ? DangerBrush : null)
.Stroke(item => item.Value > 200 ? DangerBrush : null);
Formatter = x => x + " ms";
DangerBrush = new SolidColorBrush(Color.FromRgb(238,83,80));
DataContext = this;
}
public Func<double, string> Formatter { get; set; }
public ChartValues<ObservableValue> Values { get; set; }
public Brush DangerBrush { get; set; }
public CartesianMapper<ObservableValue> Mapper { get; set; }
private void UpdateDataOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var observable in Values)
{
observable.Value = r.Next(10, 400);
}
}
}
}

View File

@@ -0,0 +1,71 @@
<UserControl x:Class="Wpf.CartesianChart.Scatter_With_Pies.Scatter_With_Pies"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.Scatter_With_Pies"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<lvc:CartesianChart>
<lvc:CartesianChart.AxisX>
<lvc:Axis MinValue="0" MaxValue="12"
Labels="Jan, Feb, Mar, Apr, May, Jun, Jul, Agu, Sep, Oct, Nov, Dec"/>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis MinValue="200" MaxValue="600">
<lvc:Axis.Separator>
<lvc:Separator Step="50"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.VisualElements>
<lvc:VisualElement X="2" Y="250" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:VisualElement.UIElement>
<lvc:PieChart Height="20" Width="20">
<lvc:PieChart.Series>
<lvc:PieSeries Values="4" />
<lvc:PieSeries Values="7" />
<lvc:PieSeries Values="2" />
</lvc:PieChart.Series>
</lvc:PieChart>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="9" Y="500" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:VisualElement.UIElement>
<lvc:PieChart Height="60" Width="60" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:PieChart.Series>
<lvc:PieSeries Values="6" />
<lvc:PieSeries Values="2" />
<lvc:PieSeries Values="1" />
</lvc:PieChart.Series>
</lvc:PieChart>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="5" Y="400" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:VisualElement.UIElement>
<lvc:PieChart Height="80" Width="80" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:PieChart.Series>
<lvc:PieSeries Values="6" />
<lvc:PieSeries Values="2" />
<lvc:PieSeries Values="1" />
</lvc:PieChart.Series>
</lvc:PieChart>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
<lvc:VisualElement X="6" Y="420" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:VisualElement.UIElement>
<lvc:PieChart Height="100" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center">
<lvc:PieChart.Series>
<lvc:PieSeries Values="6" />
<lvc:PieSeries Values="2" />
<lvc:PieSeries Values="1" />
</lvc:PieChart.Series>
</lvc:PieChart>
</lvc:VisualElement.UIElement>
</lvc:VisualElement>
</lvc:CartesianChart.VisualElements>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
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 Wpf.CartesianChart.Scatter_With_Pies
{
/// <summary>
/// Interaction logic for Scatter_With_Pies.xaml
/// </summary>
public partial class Scatter_With_Pies : UserControl
{
public Scatter_With_Pies()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,31 @@
<UserControl x:Class="Wpf.CartesianChart.ScatterPlot.ScatterExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.ScatterPlot"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:ScatterExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="0" Margin="10" Click="RandomizeOnClick">Randomize</Button>
<lvc:CartesianChart Grid.Row="1" LegendLocation="Bottom">
<lvc:CartesianChart.Series>
<lvc:ScatterSeries Title="Series A" Values="{Binding ValuesA}" />
<lvc:ScatterSeries Title="Series B" Values="{Binding ValuesB}"
PointGeometry="{x:Static lvc:DefaultGeometries.Diamond}" />
<lvc:ScatterSeries Title="Series C" Values="{Binding ValuesC}"
PointGeometry="{x:Static lvc:DefaultGeometries.Triangle}"
StrokeThickness="2" Fill="Transparent"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<!--setting the axis unit improved the labels rounding rule-->
<lvc:Axis Unit="1"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,51 @@
using System;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
namespace Wpf.CartesianChart.ScatterPlot
{
/// <summary>
/// Interaction logic for ScatterExample.xaml
/// </summary>
public partial class ScatterExample : UserControl
{
public ScatterExample()
{
InitializeComponent();
var r = new Random();
ValuesA = new ChartValues<ObservablePoint>();
ValuesB = new ChartValues<ObservablePoint>();
ValuesC = new ChartValues<ObservablePoint>();
for (var i = 0; i < 20; i++)
{
ValuesA.Add(new ObservablePoint(r.NextDouble()*10, r.NextDouble()*10));
ValuesB.Add(new ObservablePoint(r.NextDouble()*10, r.NextDouble()*10));
ValuesC.Add(new ObservablePoint(r.NextDouble()*10, r.NextDouble()*10));
}
DataContext = this;
}
public ChartValues<ObservablePoint> ValuesA { get; set; }
public ChartValues<ObservablePoint> ValuesB { get; set; }
public ChartValues<ObservablePoint> ValuesC { get; set; }
private void RandomizeOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
for (var i = 0; i < 20; i++)
{
ValuesA[i].X = r.NextDouble()*10;
ValuesA[i].Y = r.NextDouble()*10;
ValuesB[i].X = r.NextDouble()*10;
ValuesB[i].Y = r.NextDouble()*10;
ValuesC[i].X = r.NextDouble()*10;
ValuesC[i].Y = r.NextDouble()*10;
}
}
}
}

View File

@@ -0,0 +1,43 @@
<UserControl x:Class="Wpf.CartesianChart.Sections.SectionsExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:sections="clr-namespace:Wpf.CartesianChart.Sections"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance sections:SectionsExample}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Row="1" Click="UpdateAllOnClick">
Move All
</Button>
<lvc:CartesianChart Name="Chart" Grid.Row="2" Series="{Binding SeriesCollection}" >
<lvc:CartesianChart.AxisY>
<lvc:Axis Name="Axis">
<lvc:Axis.Sections>
<lvc:AxisSection Value="8.5" StrokeThickness="3" Stroke="#F9D648">
<lvc:AxisSection.Fill>
<SolidColorBrush Color="#A3A3FF" Opacity=".4"></SolidColorBrush>
</lvc:AxisSection.Fill>
</lvc:AxisSection>
<lvc:AxisSection Value="4" SectionWidth="8" Label="Good">
<lvc:AxisSection.Fill>
<SolidColorBrush Color="#CDCDCD" Opacity=".4"></SolidColorBrush>
</lvc:AxisSection.Fill>
</lvc:AxisSection>
<lvc:AxisSection Value="0" SectionWidth="4" Label="Bad">
<lvc:AxisSection.Fill>
<SolidColorBrush Color="#FF8585" Opacity=".4"></SolidColorBrush>
</lvc:AxisSection.Fill>
</lvc:AxisSection>
</lvc:Axis.Sections>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,72 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.Sections
{
public partial class SectionsExample : UserControl
{
public SectionsExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(3),
new ObservableValue(5),
new ObservableValue(2),
new ObservableValue(7),
new ObservableValue(7),
new ObservableValue(4)
},
PointGeometrySize = 0,
StrokeThickness = 4,
Fill = Brushes.Transparent
},
new LineSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(3),
new ObservableValue(4),
new ObservableValue(6),
new ObservableValue(8),
new ObservableValue(7),
new ObservableValue(5)
},
PointGeometrySize = 0,
StrokeThickness = 4,
Fill = Brushes.Transparent
}
};
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var series in SeriesCollection)
{
foreach (var observable in series.Values.Cast<ObservableValue>())
{
observable.Value = r.Next(0, 10);
}
}
}
}
}

View File

@@ -0,0 +1,50 @@
<UserControl x:Class="Wpf.CartesianChart.SectionsDragable.DragableSections"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart.SectionsDragable"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance local:DragableSections}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock>Click, hold and drag any section => </TextBlock>
<TextBlock>X:</TextBlock>
<TextBlock Text="{Binding XSection}"></TextBlock>
<TextBlock>, Y:</TextBlock>
<TextBlock Text="{Binding YSection}"></TextBlock>
</StackPanel>
<lvc:CartesianChart Grid.Row="1">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="7,2,8,2,7,4,9,4,2,8"></lvc:LineSeries>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis>
<lvc:Axis.Sections>
<lvc:AxisSection Draggable="True"
Value="{Binding XSection, Mode=TwoWay}"
StrokeThickness="4"
Stroke="DarkSlateBlue"
Panel.ZIndex="99"/>
</lvc:Axis.Sections>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis>
<lvc:Axis.Sections>
<lvc:AxisSection Draggable="True"
Value="{Binding YSection, Mode=TwoWay}"
StrokeThickness="4"
Stroke="DarkSlateBlue"
Panel.ZIndex="99"/>
</lvc:Axis.Sections>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
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 Wpf.CartesianChart.SectionsDragable
{
/// <summary>
/// Interaction logic for DragableSections.xaml
/// </summary>
public partial class DragableSections : UserControl, INotifyPropertyChanged
{
private double _xSection;
private double _ySection;
public DragableSections()
{
InitializeComponent();
XSection = 5;
YSection = 5;
DataContext = this;
}
public double XSection
{
get { return _xSection; }
set
{
_xSection = value;
OnPropertyChanged("XSection");
}
}
public double YSection
{
get { return _ySection; }
set
{
_ySection = value;
OnPropertyChanged("YSection");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,53 @@
<UserControl x:Class="Wpf.CartesianChart.SectionsMouseMove.SectionMouseMoveSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:Wpf.CartesianChart.SectionsMouseMove"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ViewModel></local:ViewModel>
</UserControl.DataContext>
<Grid>
<lvc:CartesianChart MouseMove="UIElement_OnMouseMove" DataTooltip="{x:Null}">
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Values="5,6,7,9,2,4,6,5,9,7,5,10"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis LabelFormatter="{Binding Formatter}">
<lvc:Axis.Sections>
<lvc:AxisSection Value="{Binding YPointer}"
DataLabel="True"
StrokeThickness="1"
Stroke="#ff5722"
DisableAnimations="True"
DataLabelForeground="White"
Panel.ZIndex="1"/>
</lvc:Axis.Sections>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelsRotation="-25" Labels="January, February, March, April, May, Jun, July, Agust, September, October, November, December">
<lvc:Axis.Sections>
<lvc:AxisSection Value="{Binding XPointer}"
SectionWidth="1"
SectionOffset="-0.5"
Fill="#59FF5722"
Stroke="#ff5722"
StrokeThickness=".5"
DataLabelForeground="White"
DataLabel="True"/>
</lvc:Axis.Sections>
<lvc:Axis.Separator>
<lvc:Separator Step="1" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>

Some files were not shown because too many files have changed in this diff Show More