This project has moved. For the latest updates, please go here.

Line Chart

Apr 29, 2010 at 12:38 PM
Edited Apr 29, 2010 at 12:40 PM

Hello I am using EPPlus to populate an excel spreadsheet with two columns of data. I now want to take that data, and populate it into a line chart. I have tried different ways of populating the line chart but so far nothing is working. Is there any chance that this functionality is not working? If it is working could you post or e-mail me some sample code, it is possible i am just missing a minor detail. Thanks

Coordinator
Apr 29, 2010 at 1:28 PM

Sample 4 has a line chart or have a look at sample 6 (not a line chart but you add the series the same way).

Apr 30, 2010 at 1:46 AM
Edited Apr 30, 2010 at 1:48 AM

Here is my code. I am populating two columns with 32k records each. I then format the data to a number format. I took the sample from sample6 trying to implement a LineChart. Below is the code I implemented using the exampl in sample6 as you suggested. Could you take a look and see if you can see why the LineChart is not being created.

            ws.Cells.Style.ShrinkToFit = true;

            var chart = ws.Drawings.AddChart("LineChart", eChartType.Line);

            chart.SetPosition(160, 30, 800, 600);
            chart.SetSize(400, 400);
            chart.Series.Add(ExcelRange.GetAddress(1, 1, row, columns), ExcelRange.GetAddress(1, 1, row, columns));

            chart.Title.Text = "Equity Curve";

If you need the full code please let me know.

Coordinator
Apr 30, 2010 at 6:50 AM
You set the X and Y serie to the same range. Try something like...
chart.Series.Add(ExcelRange.GetAddress(1, 2, row, 2), ExcelRange.GetAddress(1, 1, row, 1));
... depending on your columns
 
Jun 13, 2010 at 12:33 AM

It has been a while since i posted.

Here is what i ended up implementing.

   ExcelPackage excelPackage = new ExcelPackage(new FileInfo(@"C:\Projects\TestingEPPlus\TestingEPPlus\TestingEPPlus\Report.xlsx"));

   ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets[1];

   ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.Line);
   
   chart.Series.Add(ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
                    ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));

   var Series = chart.Series[0];
   
   chart.Series[0].Header = "Blah";

   excelPackage.SaveAs(new FileInfo(@"C:\Projects\TestingEPPlus\TestingEPPlus\TestingEPPlus\ReportTest.xlsx"));

 Input of the report.xlsx was in the following format.

1 $10,000.00
2 $10,100.00
3 $10,200.00
4 $10,150.00
5 $10,250.00
6 $10,200.00

For some reason instead of having just series one we saw that each number on the left was in the legend. This feels wrong from the way that excel works. Can you check into this for line graphs.

 

Coordinator
Jun 13, 2010 at 7:09 PM

Hi

Im not sure I understand the problem?

I tried this code (with the lates source) and I only got one serie and one label in the legend...

           ExcelWorksheet worksheet = _pck.Workbook.Worksheets.Add("LineIssue");

           ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.Line);
           
           worksheet.Cells["A1"].Value=1;
           worksheet.Cells["A2"].Value=2;
           worksheet.Cells["A3"].Value=3;
           worksheet.Cells["A4"].Value=4;
           worksheet.Cells["A5"].Value=5;
           worksheet.Cells["A6"].Value=6;

           worksheet.Cells["B1"].Value=10000;
           worksheet.Cells["B2"].Value=10100;
           worksheet.Cells["B3"].Value=10200;
           worksheet.Cells["B4"].Value=10150;
           worksheet.Cells["B5"].Value=10250;
           worksheet.Cells["B6"].Value=10200;

            chart.Series.Add(ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
                            ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));

           var Series = chart.Series[0];
           
           chart.Series[0].Header = "Blah";

Jan
Jun 17, 2010 at 1:30 AM

Jan

I just pulled down the latest source code compiled it and am running it in a test application.

I pulled in your sample code into my test application. When i generate the chart i still get the values for A1:A6 as the legend. I am not sure what i might be doing wrong i am using 59508.

Thanks

Chris