I am writing code that writes some data to an Excel file using C# (using Office.InterOp.Excel
). Now I have to select two columns out of the 10 in the worksheet and plot a graph between the two. This has to be done using only C#.
Any ideas? Most examples I found on the net are for fixed data values. What if the data values are not known before hand?
You can use ChartObjects class.
For example;
Microsoft.Office.Interop.Excel.Range chartRange ;
Microsoft.Office.Interop.Excel.ChartObjects xlCharts =
(Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Microsoft.Office.Interop.Excel.ChartObject myChart =
(Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
Microsoft.Office.Interop.Excel.Chart chartPage = myChart.Chart;
chartRange = xlWorkSheet.get_Range("A1", "d5");
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
Source: http://csharp.net-informations.com/excel/csharp-excel-chart.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With