Macros/Basic/Calc/Graphs

From The Document Foundation Wiki
Jump to navigation Jump to search
Other languages:
English • ‎español • ‎italiano

Return to Index

Graphs in Calc

Columns

The default type for all new charts is Columns

 1sub main()
 2dim mRangos(0)
 3dim rec as new com.sun.star.awt.Rectangle
 4
 5    doc = ThisComponent
 6    sheet = doc.CurrentController.ActiveSheet
 7    charts = sheet.charts
 8	
 9    chart_name = "MySuperGraph"
10    if charts.hasByName(chart_name) then
11        MsgBox "Chart exists"
12        exit sub
13    end if
14	
15    cell = sheet.getCellRangeByName("A1")
16    cursor = sheet.createCursorByRange(cell)
17    cursor.collapseToCurrentRegion()
18    mRangos(0) = cursor.RangeAddress	
19	
20    with rec
21        .X = 6000
22        .Y = 0         
23        .Width = 10000
24        .Height = 10000
25    end with
26	
27    charts.addNewByName(chart_name, rec, mRangos, True, True)	
28	
29end sub

Make graph columns

Bars

For change to bars, just change orientation.

1    charts.addNewByName(chart_name, rec, mRangos, True, True)	
2    chart = charts.getByName(chart_name).EmbeddedObject
3    chart.Diagram.Vertical = True

Make graph bars

Pie

1    charts.addNewByName(chart_name, rec, mRangos, True, True)	
2    chart = charts.getByName(chart_name).EmbeddedObject
3    chart.Diagram = chart.createInstance("com.sun.star.chart.PieDiagram")