Can I create a chart in Excel using EPPlus using in memory data instead of sheet data in C#?

  Kiến thức lập trình

I have created some charts for data in Excel using EPPlus. So far things are working great. An example of a chart code is below.

var weekly = worksheetWeekly.Drawings.AddChart("Weekly", eChartType.Area);
weekly.SetPosition(1, 0, 1, 0);
weekly.SetSize(1300, 500);
weekly.Title.Text = "Weekly Plan vs Actual vs Forecast - " + historyModel.WBSCode;
weekly.YAxis.Title.Text = headers[0].UOM;
var series1 = weekly.Series.Add(dataSheet.Cells["B3:B" + dataSheet.Dimension.End.Row], dataSheet.Cells["A3:A" + dataSheet.Dimension.End.Row]);
var series2 = weekly.Series.Add(dataSheet.Cells["C3:C" + dataSheet.Dimension.End.Row], dataSheet.Cells["A3:A" + dataSheet.Dimension.End.Row]);
var series3 = weekly.Series.Add(dataSheet.Cells["D3:D" + dataSheet.Dimension.End.Row], dataSheet.Cells["A3:A" + dataSheet.Dimension.End.Row]);
series1.Header = "Plan";
series2.Header = "Actual";
series3.Header = "Forecast";

As you can see, the 3 series point to colum selections for the data source the chart will use. However, I need to create a chart using some really complicated data, and I really don’t want to go to the exetent of exporting all that data to the sheet itself.

So, is it possible to create a chart for Excel where the data source for the series is data that’s in memory?

I don’t care if the chart, when it’s shown on the export, is no longer connected to any data. I just want to be able to use the data to create the chart without having to export that data in the actual file. For example, instead of the series code above, it might look like:

var series1 = weekly.series.Add(X-Axis data, y-Axis data)
var series2 = weekly.series.Add(X-Axis data, y-Axis data)
var series3 = weekly.series.Add(X-Axis data, y-Axis data)

Is this possible?