How to Draw multiple charts in single sheet

How to draw multiple charts in single sheet and also give position to the charts so they don't overlap or hide eachother.

Thanks


4 Replies

JS Janakiraman Sakthivel Syncfusion Team July 9, 2021 02:51 AM UTC

Hi ZARGHAM NAZEER MALIK, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your reported requirement and we are able to load multiple charts in a single sheet and also We are able to change the position of the chart through using drag and drop. Please find the below code snippet:  
  
<e-spreadsheet-cell> 
     <e-cell-charts> 
           <e-cell-chart type="StackingColumn" range="A2:A10"></e-cell-chart> 
      </e-cell-charts> 
</e-spreadsheet-cell> 
<e-spreadsheet-cell index=15> 
     <e-cell-charts><e-cell-chart type="StackingBar" range="A12:A20"></e-cell-chart></e-cell-charts> 
</e-spreadsheet-cell> 


this.insertChart([{ type: 'StackingColumn100', range: 'A4:A20', height: 200, width: 400 }]); 
 
 
 
For your convenience, we have prepared the sample for this. Please find the link below.
 
 
For more details, please refer the below links. 
 
 
 
Could you please check the above sample and get back to us, if you need any further assistance on this. 
 
Regards, 
Janakiraman S. 



ZN ZARGHAM NAZEER MALIK replied to Janakiraman Sakthivel July 9, 2021 08:49 AM UTC

Thanks for your support. But I want to export my data into pdf. I'm currently using following code:


using (ExcelEngine excelEngine = new ExcelEngine())

            {

                IApplication application = excelEngine.Excel;

                application.DefaultVersion = ExcelVersion.Excel2013;

                IWorkbook workbook = application.Workbooks.Create(2);


                IWorksheet sheet = workbook.Worksheets[0];


                IListObject table = sheet.ListObjects.Create("Table1", sheet["A21:C26"]);

                table.Name = "SalesTable";

                table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium9;

                //Inserts the sample data for the chart

                sheet.Range["A21"].Text = "Month";

                sheet.Range["B21"].Text = "Product A";

                sheet.Range["C21"].Text = "Product B";


                //Months

                sheet.Range["A22"].Text = "Jan";

                sheet.Range["A23"].Text = "Feb";

                sheet.Range["A24"].Text = "Mar";

                sheet.Range["A25"].Text = "Apr";

                sheet.Range["A26"].Text = "May";


                //Create a random Data

                Random r = new Random();

                for (int i = 22; i <= 26; i++)

                {

                    for (int j = 2; j <= 3; j++)

                    {

                        sheet.Range[i, j].Number = r.Next(0, 500);

                    }

                }

                IChartShape chart = sheet.Charts.Add();


                //Set chart type

                chart.ChartType = ExcelChartType.Pie;


                //Set Chart Title

                chart.ChartTitle = "Product Sales comparison";


                //Set first serie

                IChartSerie productA = chart.Series.Add("ProductA");

                productA.Values = sheet.Range["B22:B26"];

                productA.CategoryLabels = sheet.Range["A22:A26"];


                //Set second serie

                IChartSerie productB = chart.Series.Add("ProductB");

                productB.Values = sheet.Range["C22:C26"];

                productB.CategoryLabels = sheet.Range["A22:A26"];


                sheet.UsedRange.AutofitColumns();

                //Saving the workbook as stream

                //FileStream stream1 = new FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite);

                //workbook.SaveAs(stream1);


                //Initialize XlsIO renderer.

                XlsIORenderer renderer = new XlsIORenderer();


                //Convert Excel document into PDF document

                Syncfusion.Pdf.PdfDocument pdfDocument = renderer.ConvertToPDF(sheet);


                MemoryStream stream = new MemoryStream();

                pdfDocument.Save(stream);


                stream.Flush(); //Always catches me out

                stream.Position = 0; //Not sure if this is required

                                     //stream.Dispose();


                return File(stream, "application/pdf", "chart.pdf");

            }



ZN ZARGHAM NAZEER MALIK replied to ZARGHAM NAZEER MALIK July 9, 2021 08:50 AM UTC

I just want multiple graphs in my pdf file.



JS Janakiraman Sakthivel Syncfusion Team July 14, 2021 03:06 AM UTC

Hi ZARGHAM NAZEER MALIK, 
 
Thank you for your update. 
 
We have checked your reported requirement . We can achieve your requirement using  save method . Please refer below code snippets. 
 
 
function saveFile() { 
                var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet'); 
                spreadsheetObj.save({ url: 'https://ej2services.syncfusion.com/production/web-services/api/spreadsheet/save', fileName: "Sample", saveType: "Pdf" }); 
} 

Please find the link below.
 
 
  
Could you please check the above link and get back to us, if you need any further assistance on this. 
 
Regards, 
Janakiraman S. 


Loader.
Up arrow icon