This is a migrated thread and some comments may be shown as answers.

Print zoomed chartview

1 Answer 57 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Rata
Top achievements
Rank 1
Rata asked on 13 Jan 2017, 11:53 AM

I have large chart, so i zoom it to scroll.

I want to print it using something like Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(chart, stream, new PngBitmapEncoder());

I wonder will it save only current zoomed part or all chart? Because i need all chart, not only zoomed part.

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 18 Jan 2017, 11:25 AM
Hello Rata,

The ExportToImage() method takes the UI element as it is rendered. Thus, when exporting a zoomed chart, the image will contain only this part that is visualized. 

To export the whole control without zooming, you can reset the zoom properties only to export the chart:
Size previousZoom = this.chart.Zoom;
Size chartSize = new Size(this.chart.ActualWidth, this.chart.ActualHeight);
double previousZoomVerticalStart = this.chart.VerticalZoomRangeStart;
double previousZoomVerticalEnd = this.chart.VerticalZoomRangeEnd;
double previousZoomHorizontalStart = this.chart.HorizontalZoomRangeStart;
double previousZoomHorizontalEnd = this.chart.HorizontalZoomRangeEnd;
 
this.chart.Zoom = new Size(1, 1);
 
this.chart.Measure(Size.Empty);
this.chart.Measure(chartSize);
this.chart.Arrange(new Rect(chartSize));
this.chart.UpdateLayout();
 
Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(this.chart, "sample.png", new PngBitmapEncoder());
 
this.chart.Zoom = previousZoom;
this.chart.VerticalZoomRangeStart = previousZoomVerticalStart;
this.chart.VerticalZoomRangeEnd = previousZoomVerticalEnd;
this.chart.HorizontalZoomRangeStart = previousZoomHorizontalStart;
this.chart.HorizontalZoomRangeEnd = previousZoomHorizontalEnd;
 
this.chart.Measure(Size.Empty);
this.chart.Measure(chartSize);
this.chart.Arrange(new Rect(chartSize));
this.chart.UpdateLayout();

Hope this is helpful.

Regards,
Tanya
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Rata
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or