Hello!
When i exporting diagramm it's shrink image in strange way.
I use Save method of sfChart with filename.
Chart is places in Grid
|
string fileName = "ExportedChart.png";
FrameworkElement element = chart;
string imageExtension = null;
imageExtension = new FileInfo(fileName).Extension.ToLower(System.Globalization.CultureInfo.InvariantCulture);
BitmapEncoder imgEncoder = null;
imgEncoder = new PngBitmapEncoder();
if (element != null)
{
DrawingVisual visual = new DrawingVisual();
using (DrawingContext context = visual.RenderOpen())
{
var brush = new VisualBrush(element) { Stretch = Stretch.Fill };
context.DrawRectangle(brush, null, new Rect(0, 0, element.ActualWidth, element.ActualHeight));
context.Close();
}
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(visual);
imgEncoder.Frames.Add(BitmapFrame.Create(bitmap));
using (Stream stream = File.Create(fileName))
{
imgEncoder.Save(stream);
}
}
} |
Got some crop on the right side (legend)
<syncfusion:SfChart.Legend>
<syncfusion:ChartLegend
Margin="0,0,0,5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="Black"
BorderThickness="1"
CheckBoxVisibility="Visible"
CornerRadius="5"
DockPosition="Right"
IconHeight="10"
IconVisibility="Collapsed"
IconWidth="10"
ItemMargin="5" />
</syncfusion:SfChart.Legend>