1. Tag Results
chart-to-image (5)
1 - 5 of 5
How to create a chart and save as an image using ASP.NET Core Presentation library
Syncfusion Presentation is a .NET PowerPoint Library used to create, read, edit and convert PowerPoint files to PDF and images programmatically without Microsoft Office or interop dependencies. Using this library, you can create a chart and save as an image using C#. Steps to create a chart and save as an image Create a new C# console application project. Install the Syncfusion.PresentationRenderer.Net.Core NuGet package as a reference to your .NET applications from NuGet.org. Include the following namespace in the Program.cs file. C# using Syncfusion.OfficeChart; using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; Use the following code example to create a chart and save as an image using the PowerPoint library. C# //Creates a Presentation instance IPresentation pptxDoc = Presentation.Create(); //Adds a blank slide to the Presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Add a Pie chart IPresentationChart pieChart = CreatePieChart(slide); //Initialize the PresentationRenderer pptxDoc.PresentationRenderer = new PresentationRenderer(); // Converts the chart to image. Stream image = new FileStream("../../../ChartToImage.jpg", FileMode.Create, FileAccess.ReadWrite); pptxDoc.PresentationRenderer.ConvertToImage(pieChart, image); //Closes the presentation pptxDoc.Close(); image.Close(); Add the below helper methods to create a chart. C# IPresentationChart CreatePieChart(ISlide slide) { //Adds chart to the slide with position and size IPresentationChart chart = slide.Charts.AddChart(100, 10, 500, 300); chart.ChartType = OfficeChartType.Pie; //Assign data chart.DataRange = chart.ChartData[2, 1, 6, 2]; chart.IsSeriesInRows = false; //Set data to the chart- RowIndex, columnIndex, and data chart.ChartData.SetValue(1, 1, "Food"); chart.ChartData.SetValue(2, 1, "Fruits"); chart.ChartData.SetValue(3, 1, "Vegetables"); chart.ChartData.SetValue(4, 1, "Dairy"); chart.ChartData.SetValue(5, 1, "Protein"); chart.ChartData.SetValue(6, 1, "Grains"); chart.ChartData.SetValue(1, 2, "Percentage"); chart.ChartData.SetValue(2, 2, 36); chart.ChartData.SetValue(3, 2, 14); chart.ChartData.SetValue(4, 2, 13); chart.ChartData.SetValue(5, 2, 28); chart.ChartData.SetValue(6, 2, 9); //Set Chart Title chart.ChartTitle = "Pie Chart"; return chart; } A complete working sample of creating a chart and saving as an image using the PowerPoint library using C# can be downloaded from GitHub. By executing the program, you will get the image as follows. Take a moment to peruse the documentation, where you can find basic PowerPoint Presentation processing options along with features like, find and replace text, working with charts, animation, smart arts and many more in the PowerPoint Presentation, and most importantly PDF conversion with code examples. Explore more about the rich set of Syncfusion PowerPoint Framework features. Conclusion I hope you enjoyed learning about how to create a chart and save as an image using ASP.NET Core Presentation library. You can refer to our ASP.NET Core Presentation feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core Presentation example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
How to export the pie chart as an image (SfCircularChart) ?
In this article, we explain how to export the pie chart as an image using the Flutter circular chart. The SfCircularChart widget provides an option to export the chart as an image. The following steps explain how to accomplish this exporting functionality.  Step 1: Initialize the variable _chartData which stores the data source and initialize the variable _circularChartKey which stores the global key of rendering the circular chart. This key is used to convert the chart into an image. late GlobalKey<SfCircularChartState> _circularChartKey; late List<ChartSampleData> _chartData;   @override void initState() {   _circularChartKey = GlobalKey();   _chartData = < ChartSampleData >[     ChartSampleData ('Jan', 12),     ChartSampleData ('Feb', 28),     ChartSampleData ('Mar', 35),     ChartSampleData ('Apr', 47),     ChartSampleData ('Jun', 56),     ChartSampleData ('Jul', 70),   ];   super.initState(); }   class ChartSampleData {   ChartSampleData ({this.x, this.y});   final String? x;   final num? y; } Step 2: Now create the SfCircularChart widget with the PieSeries and assign the _chartData to the dataSource property and map the x, y values to xValueMapper, yValueMapper properties respectively. And also assign the _circularChartKey to the key property. SfCircularChart(   key: _circularChartKey,   series: <CircularSeries< ChartSampleData, String>>[     PieSeries< ChartSampleData, String>(       dataSource: _chartData,       xValueMapper: (ChartSampleData data, _) => data.x,       yValueMapper: (ChartSampleData data, _) => data.y     )   ], ) Step 3: Import the dart files dart:typed_data and dart.ui files to use the Uint8List, ByteData. import 'dart:typed_data'; import 'dart:ui' as ui; Step 4: Create a separate method called _renderCircularImage in which we have converted the rendered circular chart to Image by using the toImage method. Then using this Image, convert it into a byte array using toByteData method. Further creates the Uint8List from the byte array which was shown on the new page. Future<void> _renderCircularImage() async {   final ui.Image? data = await  _circularChartKey.currentState!.toImage(pixelRatio : 3.0);   final ByteData? bytes = await data!.toByteData(format : ui.ImageByteFormat.png);   final Uint8List imageBytes = bytes!.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes);   await Navigator.of(context).push<dynamic>(     MaterialPageRoute<dynamic>(       builder: (BuildContext context) {         return Scaffold(           body:Image.memory(imageBytes)         );       },     ),   ); } Step 5: Add the TextButton widget and call the _renderCircularImage method to render the chart image on a new page. @override Widget build(BuildContext context) {   return Column(     mainAxisAlignment: MainAxisAlignment.spaceEvenly,     children: <Widget>[       SfCircularChart(         key: _circularChartKey,         series: <CircularSeries<ChartSampleData, String>>[           PieSeries<ChartSampleData, String>(             dataSource: _chartData,             xValueMapper: (ChartSampleData data, _) => data.x,             yValueMapper: (ChartSampleData data, _) => data.y,           )         ]       ),       TextButton(         child: Text('Export as image'),         onPressed: () {           _renderCircularImage();         },       )     ]   ); } Now if we tap the TextButton the exported image of the circular chart will render on the new page. View the sample in GitHub.
How to avoid DPI changes while converting the Excel/Presentation/Word documents with chart into PDF
Converting Excel with charts to PDF will change the DPI. In this article, you can see different ways to avoid such DPI changes. To convert the chart from Excel ,Word and Presentation files to image/PDF, the dependent assemblies ExcelChartToImageConverter.WPF and OfficeChartToImageConverter.WPF are required. These assemblies use WPF graphical system and by default WPF applications are system DPI-aware. So, DPI will be scaled automatically when running the application with these assemblies. Due to these DPI scaling the chart images are not rendered proper. For example: the chart images might get cropped in the PDF document on PDF conversion. In this MSDN link , DPI awareness setting details for the application has been shared. Below, we have shared the set of ways available to disable DPI awareness in the application. Note:It is recommended to set in the applications, where the device DPI is not set to 96.   ​#1: Adding an attribute in the AssemblyInfo.cs Attribute ’DisableDpiAwareness’ must be added in AssemblyInfo class file. This is declared in the namespace ‘System.Windows.Media’ and should be used only when the application has the ‘WindowsBase’ assembly reference. Otherwise, options #2 or #3 can be used. C# //In AssemblyInfo.cs [assembly: System.Windows.Media.DisableDpiAwareness]   #2: Adding an application manifest file and set dpiAware value to false. If application project does not contain the ‘app.manifest’ file, it can be added in the project by adding the new item ‘Application Manifest file’. By default, the given element (i.e. dpiAware) present in the manifest file is commented. Uncomment the element and set dpiAware value to false.   XML //In app.manifest <?xml version="1.0" encoding="utf-8"?> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">   <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need to opt in.    Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->     <application xmlns="urn:schemas-microsoft-com:asm.v3">     <windowsSettings>       <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>     </windowsSettings>   </application> </assembly>   Note:If the DPI issue still persist in the application, then option #3 can be used.   #3: Calling ​SetProcessDPIAware() method in entry point of the application. The following steps are required to call the method SetProcessDPIAware(). Step #1: Declare the function ‘SetProcessDPIAware()’ from the ‘user32.dll’ using DllImport attribute. The code example to set this is given below.  C#   [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern bool SetProcessDPIAware();     Step #2: invoke the method ‘SetProcessDPIAware()’ in the entry point of the application. The entry point of the applications is different, based on the project types. Mostly, the Console and Desktop application has the entry point as ‘static void Main(string[] args)’ web application has the entry point as ‘protected void Application_Start()’. Invoke the method as in following code example. C#      //In Main Method (Console or Desktop application)      static void Main(string[] args)      {        //Call the SetProcessDPIAware() method at initial line        if (Environment.OSVersion.Version.Major >= 6)             SetProcessDPIAware();        //...Other Codes       }   C#      //In Application_Start Method (Web application)      protected void Application_Start()      {        //Call the SetProcessDPIAware() method at initial line        if (Environment.OSVersion.Version.Major >= 6)             SetProcessDPIAware();        //...Other Codes       }   Using any of these options will help you avoid DPI changes while converting Excel, Word, and PowerPoint files with chart into image or PDF.  
How to Export and Save Excel Chart as Image?
The Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, open, and edit Excel documents without the dependency of interop Excel library. Also, converts Excel documents to image, PDF, HTML, and much more. This article demonstrates how to export and save Excel chart as image in C# and VB.NET by using Syncfusion Excel (XlsIO) library. Steps to export and save Excel chart as image, programmatically: Step 1: Create a new C# console application project. Create a new C# console application Step 2: Install Syncfusion.ExcelChartToImageConverter.WinForms NuGet package as a reference to your .NET Framework applications from the NuGet.org. Install ExcelChartToImageConverter NuGet package   Step 3: Include the following namespaces in the Program.cs file. C# using Syncfusion.XlsIO; using Syncfusion.ExcelChartToImageConverter; using System.IO; using System.Drawing;   VB.NET Imports Syncfusion.XlsIO Imports Syncfusion.ExcelChartToImageConverter Imports System.IO Imports System.Drawing   Step 4: Add the below code snippet for Excel imaging or saving the file from Excel to PNG. The description of some important class members used in the code example are as follows: ExcelEngine should be initialized to access the Excel object. ChartToImageConverter should be initialized for Excel imaging. The ScalingMode property can be used to set the quality of the image. The Open() method of IWorkbooks interface opens the existing Excel workbook from the specified location. Moreover, you can also open the specified stream. You can access any of the Worksheets with its zero-based index for further manipulations. Similarly, you can access any of the Charts with its zero-based index. Most importantly, the SaveAsImage() method can be used to save Excel chart as image. The following code snippet in C# and VB.NET exports and saves the Excel chart as image file in PNG format. C# //Instantiate the spreadsheet creation engine using (ExcelEngine excelEngine = new ExcelEngine()) {     //Initialize application     IApplication application = excelEngine.Excel;       //Set default application version     application.DefaultVersion = ExcelVersion.Xlsx;       //Instantiate chart to image converter for Excel imaging     application.ChartToImageConverter = new ChartToImageConverter();       //Set the image quality     application.ChartToImageConverter.ScalingMode = ScalingMode.Normal;       //Open the existing Excel workbook containing chart     string inputFileName = "Sample.xlsx";     IWorkbook workbook = application.Workbooks.Open(inputFileName, ExcelOpenType.Automatic);       //Access the first worksheet from the worksheets collection     IWorksheet worksheet = workbook.Worksheets[0];       //Access the first chart from the charts collection     IChart chart = worksheet.Charts[0];       //Create the memory stream for chart image     MemoryStream chartStream = new MemoryStream();       //Save Excel chart as image     chart.SaveAsImage(chartStream);     chartStream.Position = 0;       //Get the image file from stream     Image image = Image.FromStream(chartStream);       //Save the image in png format     image.Save("Output.png");                }   VB.NET 'Instantiate the spreadsheet creation engine Using excelEngine As ExcelEngine = New ExcelEngine       'Initialize application     Dim application As IApplication = excelEngine.Excel       'Set default application version as Xlsx     application.DefaultVersion = ExcelVersion.Xlsx       'Instantiate chart to image converter for Excel imaging     application.ChartToImageConverter = New ChartToImageConverter()       'Set the image quality     application.ChartToImageConverter.ScalingMode = ScalingMode.Normal       'Open the existing Excel workbook containing chart     Dim inputFileName As String = "Sample.xlsx"     Dim workbook As IWorkbook = application.Workbooks.Open(inputFileName, ExcelOpenType.Automatic)       'Access the first worksheet from the worksheets collection     Dim worksheet As IWorksheet = workbook.Worksheets(0)       'Access the first chart from the charts collection     Dim chart As IChart = worksheet.Charts(0)       'Create the memory stream for chart image     Dim chartStream As MemoryStream = New MemoryStream()       'Save Excel chart as image     chart.SaveAsImage(chartStream)     chartStream.Position = 0       'Get the image file from stream     Dim image As Image = image.FromStream(chartStream)       'Save the image in png format     image.Save("Output.png") End Using   A complete working example of Excel to PNG along with the input Excel file used can be downloaded from Export and Save Excel Chart as Image.zip. By executing the program, you will get the Excel imaging output as shown below. Excel to PNG image output Take a moment to explore the rich set of Syncfusion Excel (XlsIO) library features. Besides, here is an online sample link to open Excel file. To learn more about the Syncfusion Excel (XlsIO) library, refer to the documentation where you will find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions with code examples. See Also:   Utility to compare chart images converted using Microsoft Excel and Syncfusion XlsIO How to set image quality during chart to image or PDF conversion in C#, VB.NET? Is Chart to image conversion is supported in .net framework 3.5? Create an Excel file in C# and VB.NET How to convert Excel to PDF in C#, VB.NET Convert Excel file to CSV in C# and VB.NET Create Excel from DataTable in C# and VB.NET Create an Excel file in ASP.NET Core Create an Excel file in ASP.NET MVC Create an Excel file in ASP.NET Web Forms Create an Excel file in WPF Create an Excel file in UWP Create an Excel file in Xamarin Create an Excel file in Xamarin.Android Create an Excel file in Xamarin.iOS Create an Excel file in Azure platform Read Excel file in C#, VB.NET   Note:Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering Syncfusion license key in your application to use the components without trial message.    
Utility to compare chart images converted using Microsoft Excel and Syncfusion XlsIO
Chart comparison utility is a c# project developed to compare images of charts converted using Microsoft Excel and WinForms XlsIO. This article explains the steps to run the utility.   Assemblies Required Syncfusion.XlsIO.Base.dll Syncfusion.Compression.Base.dll Syncfusion.ExcelChartToImageConverter.dll Syncfusion.SfChart.WPF.dll Microsoft.Office.Interop.Excel.dll   Refer the assemblies to project   Install XlsIO assemblies with NuGet - In Visual Studio, select Tools -> NuGet Package Manager -> Package Manager Console and execute the below command for the Console project.   Install-package Syncfusion. ExcelChartToImageConverter.WPF45 –source http://nuget.syncfusion.com/windows-forms/   Note:The number at the end of the NuGet package name represents .NET Framework version. In the above command "Syncfusion. ExcelChartToImageConverter.WPF45" represents the XlsIO libraries for .NET Framework 4.5 (Syncfusion. ExcelChartToImageConverter.WPF40 represents the libraries for .NET Framework 4.0 respectively).     Interop assembly can be referred from its installed location. For Ex.: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll   Steps to run the application Run the Visual Studio project, which shows the below window. Charts comparison utility   Browse an Excel file with charts to compare or drag and drop the file into the application to load the charts in the workbook for comparison. Utility loaded with charts of an Excel document   Double-click any image to view in it’s actual pixels.   Image in actual pixels       Note:  i) Excel documents without chart will throw a message “Workbook has no chart!”. ii) Excel document with more charts can be compared by scrolling down the charts as shown in the below screen shot.     System Requirements .NET Framework 4.0 Microsoft Excel 2003 or above Visual Studio 2010 or above Conclusion I hope you enjoyed learning about utility to compare chart images converted using Microsoft Excel and Syncfusion XlsIO. You can refer to our WinForms XIsIO’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms XIsIO documentation to understand how to present and manipulate data. For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms XIsIO and other WinForms components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!        
No articles found
No articles found
1 of 1 pages (5 items)