VBA Chart图表外观设置
新建工作表Sheet7,数据如下:

代码
Sub sub1()
  Dim chart1 As Chart
  Set chart1 = Charts.Add
  chart1.SetSourceData Source:=Sheets("Sheet7").Range("B2:B14,E2:E14")
  chart1.ChartType = xlColumnClustered '柱状图
  chart1.HasTitle = True
  chart1.ChartTitle.Caption = "学生成绩图表" '图的标题
  'chart1.ChartTitle.HorizontalAlignment = xlHAlignLeft '图标题的文本对齐。因为大小随文字,并且外部居中,所以无效果。
  chart1.ChartTitle.Left = 0 '图标题的位置
  'X坐标的标题
  chart1.Axes(Type:=xlCategory).HasTitle = True
  chart1.Axes(Type:=xlCategory).AxisTitle.Text = "姓名"
  'Y坐标的标题
  chart1.Axes(Type:=xlValue).HasTitle = True
  chart1.Axes(Type:=xlValue).AxisTitle.Text = "成绩" 
  'Y坐标刻度
  ' chart1.Axes(Type:=xlValue).MinimumScaleIsAuto = False
  'chart1.Axes(Type:=xlValue).MaximumScaleIsAuto = False
  'Y轴最小值
  chart1.Axes(Type:=xlValue).MinimumScale = -100
  'Y轴最大值
  chart1.Axes(Type:=xlValue).MaximumScale = 200
  '原点'的位置,如果不设置还停留在坐标值为0的点
  chart1.Axes(Type:=xlValue).CrossesAt = -100 
  'Y轴线网格线
  chart1.Axes(Type:=xlValue).HasMajorGridlines = False
  '显示数据标签
  chart1.SeriesCollection(1).ApplyDataLabels Type:=xlDataLabelsShowValue
  '隐藏图例
  'chart1.HasLegend = False
End Sub
 
运行结果
