Easy Chart - Scripting Functions
Scripting Functions
exportExcel(filename)
Description
- This function saves the chart's datasets as an Excel file. Returns a String of the complete file path chosen by the user, or None if the user canceled the save.
Parameters
- String filename - The default file name for the Save dialog.
Return
- String
Scope
- Client
print()
Description
- This function will print the chart.
Parameters
- Nothing
Return
- Nothing
Scope
- Client
setMode(mode)
Description
- Sets the current mode for the chart.
Parameters
Int mode - The mode to set the chart to. The mode options are as follows:
0 : Zoom Mode. This is the default mode, where the user can draw a zoom rectangle with the mouse pointer.
1 : Pan Mode. This mode lets the user use the mouse pointer to pan the chart to the left and right.
3 : Mark mode. This mode lets the user click near a datapoint to annotate the point with its X and Y value.
4 : X-Trace mode. This mode lets the user click and drag on the chart to see all values that fall along that X value.
Return
- Nothing
Scope
- Client
exportDatasets()
Description
- Returns an Array List of datasets, representing the time series data of each type of pen.
Parameters
- None
Return
- Array List of datasets. Each dataset represents timeseries data for set of pens. The order of the datasets are listed below.
Scope
- Client
Index order of datasets
Index | Dataset |
---|---|
0 | Tag Pens |
1 | Calculated Pens |
2 | Database Pens |
# This example will extract the Tag Pens series data that is already present in an Easy Chart, and pass it to a Power Table on the same window.
# This script could be placed on the Easy Chart's propertyChanged event.
# Filter on the name of the property
if event.propertyName == 'tagPens':
# Wrap our dataset behavor in a function, so we can pass it to system.util.invokeLater
def func():
chart = event.source
# Extract the datasets
datasets = chart.exportDatasets()
# Pass the first dataset (index 0 contains data for Tag Pens) to the Power Table
event.source.parent.getComponent('Power Table').data = datasets[0]
# Using invokeLater to provide a delay. We want this to run after the chart has finished loading the new tag.
system.util.invokeLater(func, 1000)
Extension Functions
configureChart
Description
- Provides an opportunity to perform further chart configuration via scripting. Doesn't return anything.
Parameters
Component self - A reference to the component that is invoking this function.
JFreeChart chart - A JFreeChart object. Refer to the JFreeChart documentation for API details.
Return
- Nothing
Scope
- Client
getXTraceLabel
Description
- Provides an opportunity to configure the x-trace label. Return a string to override the default label.
Parameters
Component self - A reference to the component that is invoking this function.
JFreeChart chart - A JFreeChart object. Refer to the JFreeChart documentation for API details.
String penName - The name of the pen the x-trace label applies to.
int yValue - The y-value of the pen at the x-trace location.
Return
- Nothing
Scope
- Client
onPowerTableRowsDropped
Description
- Called when the user has dropped rows from a power table on the chart. The source table must have dragging enabled.
Parameters
Component self - A reference to the component that is invoking this function.
Component sourceTable - A reference to the table that the rows were dragged from.
List rows - An array of the row indicies that were dragged, in the order they were selected.
Dataset rowData - A dataset containing the rows that were dragged.
Return
- Nothing
Scope
- Client
onTagsDropped
Description
- Called when the user has dropped tags from the tag tree onto the chart. Normally, the chart will add pens automatically when tags are dropped, but this default behavior will be suppressed if this extension function is implemented.
Parameters
Component self - A reference to the component that is invoking this function.
List paths - A list of the tag paths that were dropped on the chart.
Return
- Nothing
Scope
- Client
#This will take a tag that gets dropped from a Tag Browse Tree set in Realtime Tag Tree mode,
#and will replace the underscores in the name of the tag "_" and replace them with spaces.
tagPens = self.tagPens
for tag in paths:
tagPath = tag.replace("default", "~")
splitTag = tag.split("/")
name = splitTag[-1].replace("_", " ")
newRow = [name, tagPath, "MinMax", "Default Axis", 1, 1, system.gui.color(255, 85, 85, 255), "", 1, 1, 0, 1, 0, "", 0, 0, 0, 1, 0, 0]
self.tagPens = system.dataset.addRow(tagPens, newRow)
#This will take a tag that gets dropped from a Tag Browse Tree set in Realtime Tag Tree mode,
#and will place it into a Pen Group titled "My Group Name".
tagPens = self.tagPens
groupName = "My Group Name"
for tag in paths:
newRow = [name, tagPath, "MinMax", "Default Axis", 1, 1, system.gui.color(255, 85, 85, 255), "", 1, 1, 0, 1, 0, "groupName", 0, 0, 0, 1, 0, 0]
self.tagPens = system.dataset.addRow(tagPens, newRow)