0

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?

2
  • You aren't doing it in Excel, you are doing it in an OpenXML file that Excel will eventually open. You'd need to look at the Open XML spec for SpreadSheetML. I don't believe it is possible to embed (and reference) data in a file, but there are a zillion features on that file format (so there's a good chance I'm wrong). The usual way to do something like this is to put the data on one sheet and the chart on another Commented May 17, 2024 at 4:43
  • Thanks! I ended up putting the data for the chart on a hidden sheet. Seemed like the easiest alternative. Commented May 20, 2024 at 22:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.