Dan*_*nki 1 wpf charts save oxyplot
我正在尝试将图表导出到 PNG。那是我的代码:
图表.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>
Run Code Online (Sandbox Code Playgroud)
图表.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();
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用下面的代码以 PNG 格式保存图表窗口?
var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White };
pngExporter.ExportToFile(plotModel, fileName);
Run Code Online (Sandbox Code Playgroud)
我没有 plotmodel 因为我全部绑定在 xaml 中,你有什么建议吗?
小智 6
如果要从后面的代码导出,可以使用:
<oxy:Plot x:Name="Plot">
Run Code Online (Sandbox Code Playgroud)
<oxy:Plot x:Name="Plot">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2329 次 |
| 最近记录: |