Tuesday, March 13, 2012

How to create a chart in excel in asp.net

Here i will show how to create a chart in excel sheet using csharp.TO create a chart in excel we have to use Excelchart objects.Then we will give the range for this chart in excel sheet dynamically.Here i have used data set records which is having the monthly reports.Here the reports are generated for year ,so we will get the 12 reports.
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(400, 230, 350, 200);
Excel.Chart chartPage = myChart.Chart;
tempcount = "y" +noofreports.tostring;
chartRange = xlWorkSheet.get_Range("x1", tempcount);
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = Excel.XlChartType.xlLine;
//change font size of title
chartPage.ChartTitle.Characters.Font.Size = 12;
//remove majorticks
Excel.Axis x_axis = (Excel.Axis)chartPage.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
chartPage.ChartTitle.Characters.Text = "Chart in Excel sheet";
chartPage.Legend.Clear();
chartPage.HasTitle = true;
Post a Comment

Bel