作成者カテゴリ返答の対象
公開
アンヌ
08/07/2007 10:23 AM
Excelへのグラフ作成
Excelグラフ作成

あまり綺麗ではありませんが、サンプルプログラムをあげさせていただきます。
Excel VBAと比較するとわかりやすいと思います。
< Excel VBA >
Charts.Add
'グラフの種類 棒グラフ積重ね=52
ActiveChart.ChartType = xlColumnStacked
'グラフ作成エリア&行を基点として作成する
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:E10"), PlotBy:=xlRows
'Sheet1にグラフを作成する xlLocationAsObject=2
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
'グラフオプション⇒タイトルとラベルの設定
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "TEST"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X軸ラベル"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y軸ラベル"
End With
'グラフオプション⇒軸の設定
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
'グラフオプション⇒目盛線(X軸)の設定
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
'グラフオプション⇒目盛線(Y軸)の設定
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
'グラフオプション⇒データラベルの設定
ActiveChart.PlotArea.Select
ActiveChart.ApplyDataLabels AutoText:=True,_
LegendKey:=False,HasLeaderLines:=False,_
ShowSeriesName:=True, ShowCategoryName:=True, _
ShowValue:=True, ShowPercentage:=False,_
ShowBubbleSize:=False
'グラフオプション⇒凡例の設定
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
'下に表示 xlBottom=-4107
Selection.Position = xlBottom
'グラフオプション⇒データテーブルの設定
ActiveChart.HasDataTable = False

< Notes Script >
Set GraphObject = ExcelObject.Charts.Add
Const xlColumnStacked = 52
  Const xlLocationAsObject = 2
  Const xlCategory = 1
Const xlPrimary = 1
Const xlValue = 2
Const xlCategoryScale = 2
With GraphObject
  .SetSourceData(XLSSheet.Range("A3:E10")),PlotBy = xlRows
  .ChartType = xlColumnStacked 'グラフの種類
  .HasTitle = True 'グラフタイトル
  .ChartTitle.Characters.Text = カテゴリ名
  .PlotArea.Select
  .HasAxis(xlCategory, xlPrimary) = True
  .HasAxis(xlValue, xlPrimary) = True
  .Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
  .Axes(xlCategory).HasMajorGridlines = True
  .Axes(xlCategory).HasMinorGridlines = False
  .Axes(xlValue).HasMajorGridlines = True
  .Axes(xlValue).HasMinorGridlines = False
  .ApplyDataLabels AutoText=True, LegendKey=False,HasLeaderLines=False, _
  ShowSeriesName=True, ShowCategoryName=True,ShowValue=True, _
  ShowPercentage=False, ShowBubbleSize=False
  .Location(xlLocationAsObject) , "Sheet" & Cstr(n)
End With


[Previous Main Document]
Excelへのグラフ作成 (アンヌ)
. . Re:自己レス (アンヌ)
. . . . Re: 自己レス (すい)
. . . . . . Re:ありがとうございます (アンヌ)
. . . . . . . . Re:自己レス2 (アンヌ)
. . . . . . . . . . Excelグラフ作成 (アンヌ) * 現在地 *
[Next Main Document]