void SetupAxes(Excel._Chart oChart, string xLabel, float minX, float maxX, string yLabel, float minY, float maxY) { Excel.Axis axis = (Excel.Axis)oChart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); if (maxX != -1.0f) { axis.MaximumScale = maxX; } if (minX != -1.0f) { axis.MinimumScale = minX; } axis.HasTitle = true; axis.AxisTitle.Text = xLabel; axis = (Excel.Axis)oChart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); if (maxY != -1.0f) { axis.MaximumScale = maxY; } if (minY != -1.0f) { axis.MinimumScale = minY; } axis.HasMajorGridlines = false; axis.HasMinorGridlines = false; axis.HasTitle = true; axis.AxisTitle.Text = yLabel; }
private void ConfigureExcelChartFormat(string sheetName, string seriesName, Excel._Chart oChart) { //Serie format Excel.Series oSeries = (Excel.Series)oChart.SeriesCollection(1); oSeries.Name = seriesName; oSeries.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine; oSeries.Smooth = true; oSeries.Border.ColorIndex = 3; oSeries.Border.Weight = 3; //Plot area format oChart.PlotArea.Interior.ColorIndex = 0; oChart.PlotArea.Border.ColorIndex = 5; //X axis format Excel.Axis xAxis = (Excel.Axis)oChart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); xAxis.MajorGridlines.Border.ColorIndex = 5; xAxis.Border.ColorIndex = 5; xAxis.TickLabels.Font.Name = "Verdana"; xAxis.TickLabels.Font.Size = 8.0f; xAxis.TickLabels.AutoScaleFont = false; //Y axis format Excel.Axis yAxis = (Excel.Axis)oChart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); yAxis.TickLabels.Font.Name = "Verdana"; yAxis.TickLabels.Font.Size = 8.0f; yAxis.TickLabels.AutoScaleFont = false; yAxis.Border.ColorIndex = 5; yAxis.MajorTickMark = Microsoft.Office.Interop.Excel.XlTickMark.xlTickMarkNone; //Legend format oChart.Legend.Font.Name = "Verdana"; oChart.Legend.Font.Size = 9.0f; oChart.Legend.Font.Bold = true; oChart.Legend.AutoScaleFont = false; oChart.Legend.Position = Microsoft.Office.Interop.Excel.XlLegendPosition.xlLegendPositionTop; //Chart format oChart.HasTitle = false; oChart.Location(Excel.XlChartLocation.xlLocationAsObject, sheetName); }