Top > OOoBasic > Calc > chart2 > AddCharts

チャートの挿入 Edit

チャートの挿入は基本的に chart api と同じです。OOoBasic/Calc/charts

チャートの挿入1 Edit

OOoBasic/Calc/charts

addNewByName メソッドでチャートを新規挿入する際にチャート名が他のシート中にあるチャートの名前と同じ場合エラーになります。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
Sub chart2_1
  oDoc = ThisComponent
  oCharts = oDoc.getSheets().getByIndex(0).getCharts()
  
  Dim aRange(1) As New com.sun.star.table.CellRangeAddress
  Dim aRectangle As New com.sun.star.awt.Rectangle
  
  sChartName = "Chart2"
  aRange(0) = make_CellRangeAddress(0, 0, 0, 2, 6)
  aRange(1) = make_CellRangeAddress(0, 1, 1, 2, 6)
  
  aRectangle = make_Rectangle(1300, 11300, 7000, 5000)
 
  If NOT oCharts.hasByName(sChartName) Then
    oCharts.addNewByName(sChartName,aRectangle,aRange,False,False)
    
    oChartObj = oCharts.getByName(sChartName)
    oChart = oCharts.getByName(sChartName).getEmbeddedObject()
    
    oChart.setDiagram( _
        oChart.createInstance("com.sun.star.chart.XYDiagram"))
    oDiagram = oChart.getDiagram()
  End If
End Sub
 
 
Function make_CellRangeAddress( _
    nSheet As Integer, _
    nStartColumn As Long, nEndColumn As Long, _
    nStartRow As Long, nEndRow As Long ) _
        As com.sun.star.table.CellRangeAddress
  Dim aRangeAddress As New com.sun.star.table.CellRangeAddress
  With aRangeAddress
    .Sheet = nSheet
    .StartColumn = nStartColumn
    .EndColumn = nEndColumn
    .StartRow = nStartRow
    .EndRow = nEndRow
  End With
  make_CellRangeAddress = aRangeAddress
End Function
 
 
Function make_Rectangle( _
    nX As Long, nY As Long, _
    nWidth As Long, nHeight As Long ) _
        As com.sun.star.awt.Rectangle
  Dim aRectangle As New com.sun.star.awt.Rectangle
  With aRectangle
    .X = nX
    .Y = nY
    .Width = nWidth
    .Height = nHeight
  End With
  make_Rectangle = aRectangle
End Function

チャートの挿入2 Edit

Calc のシート上に挿入するのであれば OLE オブジェクトを挿入してチャートの CLSID を指定しても同じように作成できます。この場合、チャートの作成時にデータ範囲のアドレスなどを設定できません。

この方法で作成したチャートは系列を自分で編集する必要があります。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
Sub chart2_1
  oDoc = ThisComponent
  oSheet = oDoc.getSheets().getByIndex(0)
  oDrawPage = oSheet.getDrawPage()
  
  ' add new ole shape
  oEmbeded = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
  oDrawPage.add(oEmbeded) ' add before property settings
  
  ' size and position
  aSize = make_Size(8000, 7000)
  aPoint = make_Point(1000, 1000)
  
  oEmbeded.setSize(aSize)
  oEmbeded.setPosition(aPoint)
  
  ' chart document
  oEmbeded.CLSID = "12DCAE26-281F-416F-a234-c3086127382e"
  
  ' chart object
  oChart = oEmbeded.Model
End Sub
 
 
 
Function make_Size( nWidth As Long, nHeight As Long ) _
    As com.sun.star.awt.Size
  Dim aSize As New com.sun.star.awt.Size
  aSize.Width = nWidth
  aSize.Height = nHeight
  make_Size = aSize
End Function
 
 
Function make_Point( nX As Long, nY As Long ) _
    As com.sun.star.awt.Point
  Dim aPoint As new com.sun.star.awt.Point
  aPoint.X = nX
  aPoint.Y = nY
  make_Point = aPoint
End Function

この方法で作成したチャートのチャート名は変更できません。

チャートの種類の変更 Edit

ダイアグラム種類の変更を参照してください。


Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes