Print zoomed chartview

2 posts, 0 answers
  1. Rata
    Rata avatar
    1 posts
    Member since:
    Jan 2017

    Posted 13 Jan Link to this post

    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.

  2. Tanya
    Admin
    Tanya avatar
    506 posts

    Posted 18 Jan Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top