5

I'm having some trouble creating charts in Excel with C#. I've managed to get a chart of any kind working with the following code:

            Excel.Range chartRange; 

            Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
            Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
            Excel.Chart chartPage = myChart.Chart;

            chartRange = xlWorkSheet.get_Range("A2", "Y2");
            chartPage.SetSourceData(chartRange, misValue);
            chartPage.ChartType = Excel.XlChartType.xlColumnClustered;

Unfortunately, I'm not really sure what to do next. Here is what I want to do:

1) There are supposed to be several rows of data, but they are not next to each other (E.g. A2:Y2; A4:Y4; A6:Y6;). How do I add each of these to the chart?

2) A1:Y1 has all of the values for my legend, how would I add this in to the legend?

3) How can I change it so that each chart is created on a new tab?

Thanks!

1 Answer 1

4

Just figured out answer to question 1:

chartRange = xlWorkSheet.get_Range("B137:Y137, B139:Y139, B141:Y141", Missing.Value);

Now figured out answer to question 3:

chartPage.Location(Excel.XlChartLocation.xlLocationAsNewSheet, "Chart1");

And finally the answer to Question 2 was to simply add the row names as part of the selection, so as #2 but A instead of B.

Sign up to request clarification or add additional context in comments.

1 Comment

How did you add the row names to the selection?: "And finally the answer to Question 2 was to simply add the row names as part of the selection, so as #2 but A instead of B."

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.