Jump to content

マクロ/Basic/Calc/グラフ

From The Document Foundation Wiki
This page is a translated version of the page Macros/Basic/Calc/Graphs and the translation is 100% complete.

目次に戻る

Calc のグラフ

棒グラフ

新しく作る時のチャートの規定値のタイプは 縦棒グラフです。

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

棒グラフの作成

横棒グラフ

横棒グラフに変更するには、方向を変更するだけです。

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

横棒グラフ

円グラフ

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