Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:56:10+00:00 2026-06-14T06:56:10+00:00

I am trying to add a simple line graph in excel automatically by using

  • 0

I am trying to add a simple line graph in excel automatically by using EPPlus. I have and know the range of cells that contain the data that I want to use. I want the graph to look like the following:

enter image description here

The Before and After columns go on for a lot more than what is shown.

I am using this code to create the graph and position it, but I am not sure how to set the data that the graph uses:

ExcelChart ec = ws.Drawings.AddChart("Line Time Graph", OfficeOpenXml.Drawing.Chart.eChartType.Line);
ec.Title.Text = "Benchmarks";
ec.SetPosition(_times.Count + 2, 0, 1, 0);

It might have something to do with ec.Series.Add but I am not sure how to properly use it. If you could point me in the right direction that would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:56:11+00:00Added an answer on June 14, 2026 at 6:56 am

    Hope this helps you:

    ExcelChart ec = ws.Drawings.AddChart("Line Time Graph", OfficeOpenXml.Drawing.Chart.eChartType.Line);
    ec.Title.Text = "Benchmarks";
    ec.SetPosition(_times.Count + 2, 0, 1, 0);
    ec.SetSize(800, 600);
    
    var ran1 = sheet.Cells["A3:A10"];
    var ran2 = sheet.Cells["G3:G10"]; // label range if there is. Otherwise, let select blank range then edit XML data later to remove 'c:cat' tags (bellow example)
    
    var serie1 = ec.Series.Add(ran1, ran2);
    // use serie1 variable to format and so on
    // set serie1.HeaderAddress to A2 also
    
    var ran1 = sheet.Cells["B3:B10"];
    var serie2 = ec.Series.Add(ran1, ran2);
    // use serie2 variable to format and so on
    

    Another full example I’ve just tested:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using OfficeOpenXml;
    using System.IO;
    using OfficeOpenXml.Drawing.Chart;
    
    namespace TestExcelEPPluss
    {
        class Program
        {
            static void Main(string[] args)
            {
                ExcelPackage package = new ExcelPackage();
                var sheet = package.Workbook.Worksheets.Add("TestingGraph");
    
                Random r = new Random();
                var cell = sheet.Cells["A1"];
                cell.Value = "Before";
    
                cell = sheet.Cells["B1"];
                cell.Value = "After";
    
                for (int i = 0; i < 100; i++)
                {
                    cell = sheet.Cells[i + 2, 1];
                    cell.Value = r.Next(300, 500);
                    cell = sheet.Cells[i + 2, 2];
                    cell.Value = r.Next(300, 500);
                }
    
                ExcelChart ec = (ExcelLineChart)sheet.Drawings.AddChart("chart_1", eChartType.Line);
                ec.SetPosition(1, 0, 3, 0);
                ec.SetSize(800, 300);
                //ec.Legend.Add();
    
                var ran1 = sheet.Cells["A2:A101"];
                var ran2 = sheet.Cells["0:0"];
    
                var serie1 = (ExcelLineChartSerie)ec.Series.Add(ran1, ran2);
                serie1.Header = sheet.Cells["A1"].Value.ToString();
    
                ran1 = sheet.Cells["B2:B101"];
                var serie2 = ec.Series.Add(ran1, ran2);
                serie2.Header = sheet.Cells["B1"].Value.ToString();
    
                var xml = ec.ChartXml;
                var lst = xml.GetElementsByTagName("c:lineChart");
                foreach (System.Xml.XmlNode item in lst[0].ChildNodes)
                {
                    if (item.Name.Equals("ser"))
                    {
                        foreach (System.Xml.XmlNode subitem in item.ChildNodes)
                        {
                            if (subitem.Name.Equals("c:cat"))
                            {
                                item.RemoveChild(subitem);
                                break;
                            }
                        }
                    }
                }
    
                string path = @"C:\test1.xlsx";
                File.WriteAllBytes(path, package.GetAsByteArray());
                package.Dispose();
    
                Console.WriteLine("Done - Path: {0}", path);
                Console.ReadLine();
            }
        }
    }
    

    c:cat is the category for ser series, let remove c:cat tags from charts xml, then your chart will use 1,2,3,4,5,... as default for the category (x axis here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying a very simple override. I just want to add one line
I'm using Magento Community Edition ver. 1.6.2.0. I’m trying to add a Simple product
I am trying to add an attribute using javax.xml.bind.annotation to a simple type (String
I have an array of objects that I'm trying to add to the Items
So I'm trying to just add a simple ad to my app using admob.
I'm trying to create a simple service using ASP.NET MVC2. I'm using Poster add-on
I'm trying to add simple login page to ASP.NET MVC app. I actually use
I am trying to add a simple log in with Facebook button to my
I am trying to add a simple form to allow my users to edit
I'm trying to add some simple peer-to-peer connection functionality to an iOS library. Coding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.