Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hello my friends

I have a problem with my program,I am using Class "Microsoft.Office.Interop.Excel" and I can not control the Excel chart,This means that I want create a chart from only one column but it create a chart from all column.

I am using this code from Microsoft Web Site:
https://support.microsoft.com/en-us/kb/302084[^]

please help me.
Posted

1 solution

I think you would have to create a dataseries manually and consume the data that way:
http://clear-lines.com/blog/post/Create-an-Excel-chart-in-C-without-worksheet-data.aspx[^]

C#
var excel = this.Application;
var workbook = excel.ActiveWorkbook;
var charts = workbook.Charts;
var chart = (Chart)charts.Add();

chart.ChartType = Excel.XlChartType.xlLine;
chart.Location(XlChartLocation.xlLocationAsNewSheet, "Tab Name");

var seriesCollection = (SeriesCollection)chart.SeriesCollection();
var series = seriesCollection.NewSeries();

series.Values = new double[] {1d, 3d, 2d, 5d};
series.XValues = new string[] {"A", "B", "C", "D"};
series.Name = "Series Name";

You could easily change this to fit your purpose.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900