This project has moved and is read-only. For the latest updates, please go here.

Can an Shape (line) be added to a Chart (yet)?

Dec 16, 2012 at 8:42 PM

I'd like to draw a scatter chart and then put a horizontal line showing the average using epplus.

I've not seen it done yet, and not sure if it's possible.  Can it be done?

Thanks, Stephen

Dec 17, 2012 at 4:57 AM
Edited Dec 17, 2012 at 5:01 AM
Here is an example that adds a average\trendline to a scatter chart:-
      FileInfo excel_new_file = new FileInfo("C:\\test1.xlsx");
      ExcelPackage excel_package = new ExcelPackage(excel_new_file)
ExcelWorksheet excel_worksheet = excel_package.Workbook.Worksheets.Add("Scatter Chart");
excel_worksheet.Cells["A1"].Value = "Daily Rainfall"; excel_worksheet.Cells["B1"].Value = "Particulate"; excel_worksheet.Cells["A2"].Value = 4.2; excel_worksheet.Cells["B2"].Value = 122; excel_worksheet.Cells["A3"].Value = 4.3; excel_worksheet.Cells["B3"].Value = 117; excel_worksheet.Cells["A4"].Value = 5.7; excel_worksheet.Cells["B4"].Value = 112; excel_worksheet.Cells["A5"].Value = 5.4; excel_worksheet.Cells["B5"].Value = 114; excel_worksheet.Cells["A6"].Value = 5.9; excel_worksheet.Cells["B6"].Value = 110; excel_worksheet.Cells["A7"].Value = 5.0; excel_worksheet.Cells["B7"].Value = 114; excel_worksheet.Cells["A8"].Value = 3.6; excel_worksheet.Cells["B8"].Value = 128; excel_worksheet.Cells["A9"].Value = 1.9; excel_worksheet.Cells["B9"].Value = 137; excel_worksheet.Cells["A10"].Value = 7.3; excel_worksheet.Cells["B10"].Value = 104; excel_worksheet.Cells["A1:B12"].AutoFitColumns(); var scatter_chart = (excel_worksheet.Drawings.AddChart("scatter chart", eChartType.XYScatter) as ExcelScatterChart); scatter_chart.Title.Text = "Particulate Levels In Rainfall"; scatter_chart.SetPosition(0, 200); scatter_chart.SetSize(800, 400); scatter_chart.Series.Add(excel_worksheet.Cells["B2:B10"], excel_worksheet.Cells["A2:A10"]); scatter_chart.Series[0].TrendLines.Add(eTrendLine.Linear);
excel_package.Save();