LibreOffice Calc XYDiagram in BASIC:设置数据点大小

时间:2014-11-02 22:54:42

标签: basic libreoffice-calc

我想更改数据点的大小,这是因为制作XYDiagram如下所示。

Dim Rect As New com.sun.star.awt.Rectangle
Dim RangeAddress(0) As New com.sun.star.table.CellRangeAddress

Rect.X = 0
Rect.Y = 6666 * (x/3)

Rect.Width = 16500
Rect.Height = 6666

RangeAddress(0).Sheet = 0
RangeAddress(0).StartColumn = x+1
RangeAddress(0).StartRow = 1
RangeAddress(0).EndColumn = x+2
RangeAddress(0).EndRow = y-1

ThisComponent.Sheets(0).Charts.addNewByName(mode, Rect, RangeAddress(), False, False)
ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram _ = ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.createInstance("com.sun.star.chart.XYDiagram")

ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram.HasXAxisTitle = True
ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram.XAxisTitle.String ="Ratio"

ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram.HasYAxisTitle = True
ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram.YAxisTitle.String ="Cost"

ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Diagram.getDataRowProperties(1).lines = false

ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.HasLegend = False

ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.HasMainTitle = True
ThisComponent.Sheets(0).Charts.getByName(mode).embeddedObject.Title.String = mode

此代码将正确生成XY散点图,但这些点太大。鉴于我正在绘制数据的性质,我希望代码能够自动缩小点数,而不是改变生成的每个图形的大小。有谁知道如何编辑数据点大小?我搜索了几天怎么做但我找不到,似乎没有多少人使用libreoffice calc basic。

1 个答案:

答案 0 :(得分:0)

好像你有来自这里的代码示例:https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Charts_in_Spreadsheets 所以请阅读:https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/UNO_Tools#Debugging_tools并获取调试工具。使用这样的工具,您可以检查已经获得的对象。

我使用XRAY工具,在我的例子中,我检查了Chart.Diagram。我找到了https://www.openoffice.org/api/docs/common/ref/com/sun/star/chart/LineDiagram.html#SymbolSizehttps://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/Size.html

以下代码:

 Dim Doc As Object
 Dim Charts As Object
 Dim Chart as Object
 Dim Rect As New com.sun.star.awt.Rectangle
 Dim RangeAddress(0) As New com.sun.star.table.CellRangeAddress

 Doc = ThisComponent
 Charts = Doc.Sheets(0).Charts

 Rect.X = 8000
 Rect.Y = 1000
 Rect.Width = 10000
 Rect.Height = 7000
 RangeAddress(0).Sheet = 0
 RangeAddress(0).StartColumn = 0 
 RangeAddress(0).StartRow = 0
 RangeAddress(0).EndColumn = 1
 RangeAddress(0).EndRow = 11

 with Charts
  if not .hasByName("MyChart") then .addNewByName("MyChart", Rect, RangeAddress(), True, True)
  Chart = .getByName("MyChart").embeddedObject
 end with
 Chart.Diagram = Chart.createInstance("com.sun.star.chart.XYDiagram")
 'xray Chart.Diagram

 Dim Size as new com.sun.star.awt.Size
 with Size
  .Height = 150
  .Width = 150
 end with

 Chart.Diagram.SymbolSize = Size

会产生: enter image description here