【发布时间】:2018-04-06 08:36:15
【问题描述】:
我正在尝试将图表导出为 PNG。那是我的代码:
Chart.xaml
<Window x:Class="P1.Chart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:oxy="http://oxyplot.org/wpf"
xmlns:local="clr-namespace:P1"
Title="Example 1 (WPF)" Height="800" Width="800"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<oxy:Plot>
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Bottom" Minimum="-20" Maximum="20" />
<oxy:LinearAxis Position="Left" Minimum="-20" Maximum="20" />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding Points1}" LineStyle="None" MarkerType="Circle" MarkerSize="3" MarkerFill="Red" Title="Point 1"/>
<oxy:LineSeries ItemsSource="{Binding Points2}" LineStyle="None" MarkerType="Circle" MarkerSize="3" MarkerFill="Green" Title="Point 2"/>
<oxy:LineSeries ItemsSource="{Binding Points3}" LineStyle="None" MarkerType="Circle" MarkerSize="3" MarkerFill="Blue" Title="Point 3"/>
</oxy:Plot.Series>
</oxy:Plot>
</Grid>
Chart.xaml.cs
namespace P1
{
public partial class Chart: Window
{
public IList<DataPoint> Points1 { get; set; }
public IList<DataPoint> Points2 { get; set; }
public IList<DataPoint> Points3 { get; set; }
public Chart(Learn x1)
{
this.Points1 = new List<DataPoint>
{
new DataPoint(Convert.ToDouble(a1),a2),
};
this.Points2 = new List<DataPoint>
{
new DataPoint(b1,b2),
};
this.Points3 = new List<DataPoint>
{
new DataPoint(c1,c2),
};
InitializeComponent();
}
是否可以使用以下代码将图表窗口保存为 PNG?
var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White };
pngExporter.ExportToFile(plotModel, fileName);
我没有 plotmodel,因为我在 xaml 中绑定了所有内容,您有什么建议吗?
【问题讨论】: