Top > OOoBasic > Calc > chart2 > AddCharts
* チャートの挿入 [#r4ed0350]

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

#contents

** チャートの挿入1 [#x66b1f23]
[[OOoBasic/Calc/charts]]

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

#code(ob){{
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 [#c5284ddf]
Calc のシート上に挿入するのであれば OLE オブジェクトを挿入してチャートの CLSID を指定しても同じように作成できます。この場合、チャートの作成時にデータ範囲のアドレスなどを設定できません。

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

#code(ob){{
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
}}

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

** チャートの種類の変更 [#ye96527d]

[[ダイアグラム種類の変更>../ChartTypeTemplate]]を参照してください。

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