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 6219915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:52:03+00:00 2026-05-24T07:52:03+00:00

I’ve spent hours now trying to create a few charts in Excel from my

  • 0

I’ve spent hours now trying to create a few charts in Excel from my C# application. I’m trying to create more than one chart object. Is there a better way of doing this? I’m sure the line “chartObject[col] = (Excel.Chart)oWB.Charts.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);” is where I’m going wrong.

At the moment, when I call this line, it sometimes creates a a copy of the last chart, but sometimes it works. I can’t understand the logic to it at all.

Thanks

private void CreateCharts(Excel.Worksheet oWS, int numRows, int numCols)
    {
        Excel.Workbook oWB = (Excel.Workbook)oWS.Parent;
        Excel.Series oSeries;
        //Excel._Chart chartObject;
        Excel.Chart[] chartObject = new Excel.Chart[numCols];
        Excel.SeriesCollection[] oSeriesCollection = new Excel.SeriesCollection[numCols];
        int length = numRows + 2;
        string colname;

        //then you can assign as much as series you want,
        for (int col = 0; col < numCols; col++)
        {
            //create a new chart
            chartObject[col] = (Excel.Chart)oWB.Charts.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            chartObject[col].ChartType = Excel.XlChartType.xlLine;
            oSeriesCollection[col] = (Excel.SeriesCollection)chartObject[col].SeriesCollection();

            //add the actual occupancy
            colname = GetExcelColumnName(col * 3 + 1);
            oSeries = oSeriesCollection[col].NewSeries();
            oSeries.Values = oWS.Range[colname + "2", colname + length];

            //add the expected occupancy
            colname = GetExcelColumnName(col * 3 + 2);
            oSeries = oSeriesCollection[col].NewSeries();
            oSeries.Values = oWS.Range[colname + "2", colname + length];
        }
    }
  • 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-05-24T07:52:04+00:00Added an answer on May 24, 2026 at 7:52 am

    The problem my be that the Chart object in Excel is really a chart sheet, while a chart itself is a ChartObject object, and you use the Shape object it’s in to handle it. Here’s a link, and another one that talke about it a abit, and some VBA code from this MS link that shows a little of it, note that there are a few different ways to get it done:

    Sub AddChart_Excel()   
      Dim objShape As Shape   
    
      ' Create a chart and return a Shape object reference.   
      ' The Shape object reference contains the chart.   
      Set objShape = ActiveSheet.Shapes.AddChart(XlChartType.xlColumnStacked100)   
    
      ' Ensure the Shape object contains a chart. If so,   
      ' set the source data for the chart to the range A1:C3.  
      If objShape.HasChart Then  
        objShape.Chart.SetSourceData Source:=Range("'Sheet1'!$A$1:$C$3")  
      End If  
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters

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.