例1 
最も基本的なものとして
- 新たなチャートを作成
- 種類を変更
- 新しいデータ範囲を設定
する例です。すべて chart2 モジュールを利用するようにします。
簡単な表から 3Dの円グラフを作成します。範囲は Sheet1.A1:B3 です。

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
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
oCharts.addNewByName(sChartName,aRectangle,aRange,False,False)
oChart = oCharts.getByName(sChartName).getEmbeddedObject()
oDiagram = oChart.getFirstDiagram()
oChartTypeManager = oChart.getChartTypeManager()
oChartTypeTemplate = oChartTypeManager.createInstance( _
"com.sun.star.chart2.template.ThreeDPie")
oChartTypeTemplate.changeDiagram(oDiagram)
oDataProvider = oChart.getDataProvider()
oCoords = oDiagram.getCoordinateSystems()
oCoord = oCoords(0)
oChartTypes = oCoord.getChartTypes()
oChartType = oChartTypes(0)
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)
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