Export function

Hi,

I am missing an export function. When will it be available (like SfChart for other platforms)?

12 Replies

DV Divya Venkatesan Syncfusion Team February 19, 2018 10:27 AM UTC

Hi Vince,

Thanks for using Syncfusion products.

We don’t have built-in support to export the Chart in Xamarin.Android. However, we have prepared a sample for exporting chart as image. Please download it from the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/135987/ze/ExportSample-1083747832

Please let us know, if you need any further assistance on this.

Regards,
Divya Venkatesan
 



VI Vince February 19, 2018 12:48 PM UTC

Hi Divya,

On your code bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, fileStream); I got the next error:
System.NullReferenceException: Object reference not set to an instance of an object.

This is caused by your code var bitmap = chart.DrawingCache; which results in a null value for var bitmap.

Do you have a solution?





DV Divya Venkatesan Syncfusion Team February 20, 2018 09:33 AM UTC

Hi Vince, 
 
We suspect that you have missed the below line from the sample provided in the earlier update. Could you please check whether you have added this in your application? 
 
public void SaveAsImage(string filename) 
{ 
     chart.DrawingCacheEnabled = true; 
     ... 
} 
 
Regards, 
Divya Venkatesan 
 



VI Vince February 20, 2018 10:01 AM UTC

Hi,

The code chart.DrawingCacheEnabled = true; was included. So that is not the solution.

In my case the chart is build on the fly without a layout:
var chart = new SfChart(v.Context);

Perhaps that is the reason for the error?


VI Vince February 22, 2018 10:03 AM UTC

Do you know already an idea why saving/exporting a chart to a jpg file is not working?


DV Divya Venkatesan Syncfusion Team February 22, 2018 10:35 AM UTC

Hi Vince,

We can export the chart without adding to layout by creating Bitmap from the chart using Bitmap.CreateBitmap() method and drawing the chart on the Canvas using Draw() method of view. We have attached the modified sample which can be downloaded from the below link.

Sample: http://www.syncfusion.com/downloads/support/forum/135987/ze/ExportSample1273177110

Please let us know, if you need any further assistance on this.

Regards,
Divya Venkatesan



VI Vince February 22, 2018 11:49 AM UTC

Hi Divya,

I followed your code sample but the chart is only partly visible in the exported Jpeg file. I changed your code chart.Layout(0, 0, chart.MeasuredWidth, chart.MeasuredHeight); but it does not change anything.

In my original chart I have 2 series. They are set with var series1 = new ColumnSeries();The problem now is that these series are visible when the chart is rendered on the screen but they are not visible in the exported Jpeg file.

Do you have solutions for these problems?


DV Divya Venkatesan Syncfusion Team February 23, 2018 11:05 AM UTC

Hi Vince, 
 
Could you please provide us the exported image from your application if possible? Also, please make sure the width and height of chart.LayoutParameters is same as chart.MeasuredWidth and chart.MeasuredHeight in your application? 
 
chart.LayoutParameters = new ViewGroup.LayoutParams(width, height); 
 
... 
 
chart.Layout(0, 0, chart.MeasuredWidth, chart.MeasuredHeight); 
 
Additionally, could you please check and update us whether the reported issue happening in our sample? 
 
Regards, 
Divya Venkatesan 



VI Vince March 5, 2018 03:01 PM UTC

Hi Divya,

Sorry for my late reply but after updating all kind off references (Xamarin and Syncfusion) th app crashed. Now it works again after re-installing Visual Studio and all references on my computer which took a lot of time.

I hereby send you the JPG file and the PDF file. It seems that the JPG file is all right (only the margin on the right side is to small) but when adding the JPG file in the PDF file it goes wrong because only a part of the JPG file is visible.

My code to create and save the pfd file:
            var doc = new PdfDocument();
            var page = doc.Pages.Add();
            var graphics = page.Graphics;
            var fsJPG = new FileStream(pathJPG, FileMode.Open);
            var fsPDF = new FileStream(pathPDF, FileMode.Create);
            var image = new PdfBitmap(fsJPG);
            graphics.DrawImage(image, 0, 0);
            doc.Save(fsPDF);
            doc.Close(true);
            fsJPG.Close();
            fsPDF.Close();



Attachment: JPG_and_PDF_file_6348bc6b.rar


DV Divya Venkatesan Syncfusion Team March 6, 2018 04:27 PM UTC

Hi Vince, 
  
We suspect that you have not the width and height of the image drawn in pdf. Please set the width and height of the image which is to be drawn in pdf as shown in the below code snippet. 
  
Code Snippet: 
  
graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); 
  
Please let us know, if you need any further assistance on this. 
  
Regards, 
Divya Venkatesan 
 



VI Vince March 6, 2018 04:58 PM UTC

Hi Divya,

That solves the problem.

Thanks!


DV Divya Venkatesan Syncfusion Team March 7, 2018 06:45 AM UTC

Hi Vince,

Thanks for the update. We are glad to know that the given solution works.

Please let us know if you need any further assistance.

Regards,
Divya Venkatesan


Loader.
Up arrow icon