Top > OOoBasic > Calc > chart2 > ex1

例1 Edit

最も基本的なものとして

  1. 新たなチャートを作成
  2. 種類を変更
  3. 新しいデータ範囲を設定 する例です。すべて chart2 モジュールを利用するようにします。

簡単な表から 3Dの円グラフを作成します。範囲は Sheet1.A1:B3 です。

chart_ex1.png

  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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
Sub Chart_ex1
  oDoc = ThisComponent
  ' charts container of the first sheet
  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"
  aRectangle = make_Rectangle(1300, 1300, 7000, 5000)
  
  If oCharts.hasByName(sChartName) Then
    oCharts.removeByName(sChartName)
  End If
  
  ' adds new chart
  oCharts.addNewByName(sChartName,aRectangle,aRange,False,False)
  ' get newly created chart
  oChart = oCharts.getByName(sChartName).getEmbeddedObject()
 
  ' diagram of the css.chart2
  oDiagram = oChart.getFirstDiagram()
 
  ' create template and set to it
  oChartTypeManager = oChart.getChartTypeManager()
  oChartTypeTemplate = oChartTypeManager.createInstance( _
    "com.sun.star.chart2.template.ThreeDPie")
  oChartTypeTemplate.changeDiagram(oDiagram)
  
  ' DataProvider is used to make new data source
  oDataProvider = oChart.getDataProvider()
 
  ' coordinates belongs the diagram
  oCoords = oDiagram.getCoordinateSystems()
  oCoord = oCoords(0)
 
  ' chart types belonging the coordinate
  oChartTypes = oCoord.getChartTypes()
  oChartType = oChartTypes(0)
 
  ' create new datasource from arguments
  ' valid names of arguments are defined in
  ' css.chart2.data.TabularDataProviderArguments service
  Dim aProps(3) As New com.sun.star.beans.PropertyValue
  aProps(0).Name = "CellRangeRepresentation"
  aProps(0).Value = "Sheet1.A1:B3"
  aProps(1).Name = "DataRowSource"
  aProps(1).Value = com.sun.star.chart.ChartDataRowSource.COLUMNS
  aProps(2).Name = "FirstCellAsLabel"
  aProps(2).Value = False
  aProps(3).Name = "HasCategories"
  aProps(3).Value = True
 
  oDataSource = oDataProvider.createDataSource(aProps)
  
  ' change data of the diagram
  Dim aArgs(0) As New com.sun.star.beans.PropertyValue
  aArgs(0).Name = "HasCategories"
  aArgs(0).Value = True
 
  oChartTypeTemplate.changeDiagramData(oDiagram, oDataSource, aArgs)
End Sub
 
 
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

表示されるチャートは色が手動で作成したものと少し違いますが、これは 3D データの違いによるものです。以下の様にすると同じになります。

 With oDiagram
   .D3DSceneAmbientColor = 13421772
   .D3DSceneLightColor2 = 3355443
   .D3DSceneShadowSlant = 0
 End With

Attach file: filechart_ex1.png 256 download [Information]

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