yZMaG‖SFDocuments.Chart service

nPHDK‖The Chart service provides a set of properties and methods to handle charts in Calc documents. With this service it is possible to:

mZuuF‖Chart names

QPAjE‖Charts may have two different names:

note

6CV3D‖The Chart service primarily uses the user-defined name to access a chart object. If it does not exist, than the internal name is used.


yYSdL‖Service invocation

jkE4f‖Before using the Chart service the ScriptForge library needs to be loaded or imported:

note

gF8D8‖• Basic macros require to load ScriptForge library using the following statement:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Python scripts require an import from scriptforge module:
from scriptforge import CreateScriptService


LvW6m‖The Chart service is instantiated from a Calc service instance either using the Charts or CreateChart methods.

3aa4B‖In Basic

QtZnt‖The example below creates a Chart service instance from an existing chart in the current Calc document:


    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Dim oDoc as Object, oChart as Object
    Set oDoc = CreateScriptService("Calc")
    Set oChart = oDoc.Charts("Sheet1", "Object 1")
  

Cqd8G‖The following example instantiate the Chart service by creating a new chart object based on the data contained in the range "Sheet1.A1:C10".


    Dim oDoc as Object, oChart as Object
    Set oDoc = CreateScriptService("Calc")
    Set oChart = oDoc.CreateChart("My Chart", "Sheet1", "Sheet1.A1:C10")
  
tip

eFatU‖Read the CreateChart method description to learn more about its arguments.


BenDd‖In Python

gjYRg‖The examples above can be written in Python as follows:


    from scriptforge import CreateScriptService
    doc = CreateScriptService("Calc")
    chart = doc.Charts("Sheet1", "Object 1")
  

    doc = CreateScriptService("Calc")
    chart = doc.CreateChart("My Chart", "Sheet1", "Sheet1.A1:C10")
  

QxXb9‖Properties

z42Tx‖Name

5RCfg‖Readonly

5Ckhe‖Type

EJsLr‖Description

ChartType

5yKq5‖No

String

BURxX‖Specifies the chart type as a string that can assume one of the following values: "Pie", "Bar", "Donut", "Column", "Area", "Line", "XY", "Bubble", "Net".

Deep

MEEhi‖No

Boolean

qaDDb‖When True indicates that the chart is three-dimensional and each series is arranged in the z-direction.

YkDSU‖When False series are arranged considering only two dimensions.

Dim3D

qEBab‖No

Boolean or String

gk8ns‖Specifies if the chart is displayed with 3D elements. If the value is a string, it must be either "Bar", "Cylinder", "Cone" or "Pyramid".

HgqhX‖If the boolean True value is specified, then the chart is displayed using 3D bars.

Exploded

vDs4z‖No

Numeric

m224E‖Specifies how much pie segments are offset from the chart center as a percentage of the radius. Applicable to pie and donut charts only.

Filled

hbjwH‖No

Boolean

AaBHr‖When True, specifies a filled net chart. Applicable to net charts only.

Legend

xgCB2‖No

Boolean

8YDHE‖Specifies whether or not the chart has a legend.

Percent

BNBDQ‖No

Boolean

MLPCx‖When True, chart series are stacked and each category sums up to 100%. Applicable to Area, Bar, Bubble, Column and Net charts.

Stacked

yGCZ7‖No

Boolean

Gbsst‖When True, chart series are stacked. Applicable to Area, Bar, Bubble, Column and Net charts.

Title

9Dnwe‖No

String

VwMyU‖Specifies the main title of the chart.

XTitle

FGSKV‖No

String

eH3Ag‖Specifies the title of the X axis.

YTitle

mmRtZ‖No

String

scox2‖Specifies the title of the Y axis.

XChartObj

CRLf5‖Yes

YCRTC‖UNO Object

eDWVw‖Returns the object representing the chart, which is an instance of the ScChartObj class.

XDiagram

kDUCf‖Yes

LAgXE‖UNO Object

5f7Db‖Returns the com.sun.star.chart.XDiagram object representing the diagram of the chart.

XShape

CAXYe‖Yes

yh7k9‖UNO Object

xAiNS‖Returns the com.sun.star.drawing.XShape object representing the shape of the chart.

XTableChart

DdVs9‖Yes

winTd‖UNO Object

95Sfn‖Returns the com.sun.star.table.XTableChart object representing the data being displayed in the chart.


A278T‖Creating a chart

EK2E7‖Consider the following data in the range "A1:B6" of a sheet named "Report".

A

B

1

Sample A

Sample B

2

36

40

3

39

43

4

45

40

5

52

48


ZSw7Y‖The examples below in Basic and Python show how to create a line chart from this data with legends.

3aa4B‖In Basic

    oDoc = CreateScriptService("Calc")
    oChart = oDoc.CreateChart("Samples", "Report", "Report.A1:B6")
    oChart.ChartType = "Line"
    oChart.Legend = True
    oChart.Resize(1000, 1000, 25000, 15000)
  
BenDd‖In Python

    doc = CreateScriptService("Calc")
    chart = doc.CreateChart("Samples", "Report", "Report.A1:B6")
    chart.ChartType = "Line"
    chart.Legend = True
    chart.Resize(1000, 1000, 25000, 15000)
  
tip

whbDd‖The chart does not need to be created in the same sheet where the data is located. It can be created in any existing sheet in the current file by specifying the sheet name in the second argument of the CreateChart method.


RtuMk‖Methods

mNZFS‖List of Methods in the Chart Service

ExportToFile

Resize


ExportToFile

WfVxL‖Saves the chart as an image file in a specified location. Returns True if the image file could be successfully created.

FVEx2‖Syntax:

chart.ExportToFile(filename: str, imagetype: str = "png", overwrite: bool = False): bool

WADQ4‖Parameters:

SAtUt‖filename: Identifies the path and file name where the image will be saved. It must follow the notation defined in SF_FileSystem.FileNaming.

2YEEE‖imagetype: The name of the image type to be created. The following values are accepted: "gif", "jpeg", "png" (default), "svg" and "tiff".

XRASx‖overwrite: Specifies if the destination file can be overwritten (Default = False).

EFSA4‖Example:

3aa4B‖In Basic

      oChart.ExportToFile("C:\Temp\myChart.svg", ImageType := "svg", Overwrite := True)
    
BenDd‖In Python

      chart.ExportToFile(r"C:\Temp\myChart.svg", imagetype="svg", overwrite=True)
    

Resize

MCGBa‖Changes the position of the chart in the current sheet and modifies its width and height. Returns True if resizing was successful.

FVEx2‖Syntax:

chart.Resize([xpos: int], [ypos: int], [width: int], [height: int]): bool

WADQ4‖Parameters:

aMKE5‖xpos, ypos: Specify the new X and Y positions of the chart. If any of these values are omitted or if negative values are provided, the corresponding positions are left unchanged.

qvsYR‖width: Specify the new width of the chart. If this argument is omitted or if a negative value is provided, the chart width is left unchanged.

nGioo‖height: Specify the new height of the chart. If this argument is omitted or if a negative value is provided, the chart height is left unchanged.

note

EyY7j‖All arguments are provided as integer values that correspond to 1/100 of a millimeter.


EFSA4‖Example:

3aa4B‖In Basic

      h7zov‖' Changes only X and Y position
      oChart.Rezise(1000, 3000)
      VHc2V‖' Changes only the chart width and height
      oChart.Resize(, , 25000, 12500)
      BEAYa‖' Keyword arguments are supported
      oChart.Resize(Width := 25000, Height := 12500)
    
BenDd‖In Python

      chart.Rezise(1000, 3000)
      chart.Resize(-1, -1, 20000, 20000)
      chart.Resize(width=25000, height=12500)
    
warning

uzETY‖All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.