Macros/Basic/Calc/Graphs

From The Document Foundation Wiki
Jump to navigation Jump to search
This page contains changes which are not marked for translation.
Other languages:
English • ‎español • ‎italiano

Return to Index

Graphs in Calc

Columns

The default type for all new charts is Columns

sub main()
dim mRangos(0)
dim rec as new com.sun.star.awt.Rectangle

    doc = ThisComponent
    sheet = doc.CurrentController.ActiveSheet
    charts = sheet.charts
	
    chart_name = "MySuperGraph"
    if charts.hasByName(chart_name) then
        MsgBox "Chart exists"
        exit sub
    end if
	
    cell = sheet.getCellRangeByName("A1")
    cursor = sheet.createCursorByRange(cell)
    cursor.collapseToCurrentRegion()
    mRangos(0) = cursor.RangeAddress	
	
    with rec
        .X = 6000
        .Y = 0         
        .Width = 10000
        .Height = 10000
    end with
	
    charts.addNewByName(chart_name, rec, mRangos, True, True)	
	
end sub

Make graph columns

Bars

For change to bars, just change orientation.

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

Make graph bars

Pie

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