Interface IChartToImageConverter
Represents the XlsIO Chart to image converter.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface IChartToImageConverter
Remarks
This interface is not supported in Xamarin(PCL) and NetStandard platforms and supported from .NET Framework 4.0 onwards.
Properties
ScalingMode
It represents the chart image Scaling. Default value is Normal.
Declaration
ScalingMode ScalingMode { get; set; }
Property Value
Type |
---|
ScalingMode |
Remarks
To know more about chart to image conversion refer this link.
Examples
The following code illustrates how to set scaling mode for IChartToImageConverter object.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
// Initializing the chart to image converter object
application.ChartToImageConverter = new Syncfusion.ExcelChartToImageConverter.ChartToImageConverter();
//Set the chart to image converter Scaling mode to best
application.ChartToImageConverter.ScalingMode = ScalingMode.Best;
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Initalizing the new stream
MemoryStream imageStream = new MemoryStream();
//Convert the chart to image stream
chart.SaveAsImage(imageStream);
//Saving the image stream to a file
System.Drawing.Image bitmap = System.Drawing.Image.FromStream(imageStream);
bitmap.Save("image.png");
//Dispose
workbook.Close();
}
Methods
SaveAsImage(IChart, Stream)
Converts the XlsIO chart to Image as stream.
Declaration
void SaveAsImage(IChart chart, Stream imageAsStream)
Parameters
Type | Name | Description |
---|---|---|
IChart | chart | Represents the XlsIO Chart object. |
System.IO.Stream | imageAsStream | In where the image is streamed. |
Remarks
To know more about chart to image conversion refer this link.
Examples
The following code illustrates how to convert an Excel chart to an image.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
// Initializing the chart to image converter object
application.ChartToImageConverter = new Syncfusion.ExcelChartToImageConverter.ChartToImageConverter();
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Initalizing the new stream
MemoryStream imageStream = new MemoryStream();
//Convert the chart to image stream
chart.SaveAsImage(imageStream);
//Saving the image stream to a file
System.Drawing.Image bitmap = System.Drawing.Image.FromStream(imageStream);
bitmap.Save("image.png");
//Dispose
workbook.Close();
}