-
Notifications
You must be signed in to change notification settings - Fork 569
/
View.xaml.cs
49 lines (42 loc) · 1.52 KB
/
View.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Windows.Controls;
using LiveChartsCore.SkiaSharpView.SKCharts;
using LiveChartsCore.SkiaSharpView.WPF;
namespace WPFSample.General.ChartToImage;
/// <summary>
/// Interaction logic for View.xaml
/// </summary>
public partial class View : UserControl
{
public View()
{
InitializeComponent();
// in this case, when the view is loaded // mark
// we render our chart controls as images // mark
Loaded += View_Loaded;
}
private void View_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
CreateImageFromCartesianControl();
CreateImageFromPieControl();
CreateImageFromGeoControl();
}
private void CreateImageFromCartesianControl()
{
// you can take any chart in the UI, and build an image from it // mark
var chartControl = (CartesianChart)FindName("cartesianChart");
var skChart = new SKCartesianChart(chartControl) { Width = 900, Height = 600, };
skChart.SaveImage("CartesianImageFromControl.png");
}
private void CreateImageFromPieControl()
{
var chartControl = (PieChart)FindName("pieChart");
var skChart = new SKPieChart(chartControl) { Width = 900, Height = 600, };
skChart.SaveImage("PieImageFromControl.png");
}
private void CreateImageFromGeoControl()
{
var chartControl = (GeoMap)FindName("geoChart");
var skChart = new SKGeoMap(chartControl) { Width = 900, Height = 600, };
skChart.SaveImage("MapImageFromControl.png");
}
}