我使用下面的代码(VB.Net和Microsoft Excel Interop)创建了以下图表对象
Dim ColumnChart As Microsoft.Office.Interop.Excel.Chart
Dim ColumnChartShape As Microsoft.Office.Interop.Excel.Shape = oSheet.Shapes.AddChart()
ColumnChart = ColumnChartShape.Chart
CCLastRow = oSheet.Rows.End(Excel.XlDirection.xlDown)
CCLR = oSheet.UsedRange.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell).Row
CCLC = oSheet.UsedRange.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell).Column
oSheet.Range("$C$3:" & GetExcelColumn(CCLC) & CCLastRow.Row).NumberFormat = "$#,##0_);($#,##0)"
ColumnChartSourceRange = oSheet.Range("$B$3:" & GetExcelColumn(CCLC) & CCLastRow.Row)
With ColumnChart
.ChartWizard(Source:=ColumnChartSourceRange, Title:="Purchases - " + TextPeriod1Name + " vs " + TextPeriod2Name, PlotBy:=Microsoft.Office.Interop.Excel.XlRowCol.xlColumns)
.ApplyLayout(9, Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered)
.ChartStyle = 34
.ApplyDataLabels(Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowLabel, False, False, False, False, False, True)
.SeriesCollection(1).DataLabels.Position = Microsoft.Office.Interop.Excel.XlDataLabelPosition.xlLabelPositionOutsideEnd
.SeriesCollection(1).Interior.Color = RGB(132, 175, 104)
.SeriesCollection(2).DataLabels.Position = Microsoft.Office.Interop.Excel.XlDataLabelPosition.xlLabelPositionOutsideEnd
.SeriesCollection(2).Interior.Color = RGB(19, 46, 66)
.PlotArea.Border.Weight = 1
.PlotArea.Border.Weight = 1
.PlotArea.Border.Color = ColorTranslator.ToOle(Color.Gray)
.ChartArea.Width = 563.04
.ChartArea.Height = 311.76
.ChartArea.Border.Weight = 1
.ChartArea.Border.LineStyle = 0
.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = ""
.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = ""
.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary).TickLabels.NumberFormat = "$#,##0"
.Axes(Excel.XlAxisType.xlValue).MinimumScaleIsAuto = False
.Axes(Excel.XlAxisType.xlValue).MinimumScale = 0
.ChartArea.Format.TextFrame2.TextRange.Font.Size = 12
.Legend.Format.TextFrame2.TextRange.Font.Size = 12
.ChartArea.Format.TextFrame2.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue
.Legend.Format.TextFrame2.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue