Pencil-icon.png

Generate data and make a graph

This example shows you how to generate a simple data channel in jBEAM and how to display the generated data. The most of code of this example is combined from different code snippets above.

The first thing you have to do is to start your jBEAM. After startup, you can enter the example code. So you have to click on Extra -> Miscellaneous -> Scripting. After clicking, you see the Script-Editor. There you can choose the prefered scripting language and paste the code from this example. You can also test the pasted code with the Test Script Button before executing. After click on “ok” the script will be executed.

This script does the following things:

  • generating a numeric double channel with values of the RAINFLOW_TEST
  • create a UniversalCurveGraph
  • add the generated value channel to the UniversalCurveGraph
import java.awt.Color;
import java.awt.geom.*;
import com.AMS.jBEAM.*;

// new Numeric Channel Generator Component
NumericChannelGenerator numChanGen = (NumericChannelGenerator) jC.newComponent(jbComponentIF.GEN_DOUBLE_CHANNEL);
// setting of function to generate, here Rain flow function
numChanGen.setFunction (NumericChannelGenerator.Function.RAINFLOW_TEST);
// definition of how many values to be created
numChanGen.setRequestedValues (100);
// setting of delta x
numChanGen.setDeltaX(2);
// important to display the delete button in the modification dialog of the channel
numChanGen.setVirgin(false);
// validate framework to import file and get a valid jBEAM
// If parameter block is true, validation runs in main thread if operationMode is set to jbDataItemManagerIF.NOT_THREADED until the validation is finished
jC.validateFramework(true);

// get the graphic window from jBEAM
GraphLayoutFrame layoutFrame = jG.getTopMostGraphFrame();

AbstractGraphicPanel activeGraphicPanel = layoutFrame.getActiveGraphicPanel();
// create new bounds for the graph
Rectangle2D.Float diagramBounds = new Rectangle2D.Float();
// creates a new graph and add it to the graphicpanel
UniversalCurveGraph u2DGraph = (UniversalCurveGraph) activeGraphicPanel.addNewGraph(jbVisualObjectIF.UNI_CURVE_GRAPH, diagramBounds, false);

// size values
int graphWidth = 500;
int graphHeight = 400;

// sets position and size
u2DGraph.setScreenBounds(0, 0, graphWidth, graphHeight);
// makes the graph modifyable in jBEAM
u2DGraph.setModifyable(true);
// makes the graph moveable
u2DGraph.setMoveable(true);
// makes the graph resizeable
u2DGraph.setGrowable(true);
// makes the graph printable -> important for PDF-Export
u2DGraph.setPrintable(true);
// used for index in border
u2DGraph.setComponentIndex(0);
// to hide the legend
u2DGraph.getLegende().setVisible(false);
// set title of the graph
u2DGraph.getTitle().setName("Example");
// delets all existing curves from the graph
u2DGraph.deleteAllCurves();

// creates a new XY_Curve
XY_Curve curve = new XY_Curve(u2DGraph);
// sets the input data from the generator to the curve
curve.setYInputChannel(numChanGen.getResultObjects()[0]);
// sets the line color of the curve
curve.getLine().setColor(Color.BLUE);
// adds curve to the graph
u2DGraph.addCurve(curve);

u2DGraph.redraw();

After the execution of this code you see a curvegraph, which displays the generated RAINFLOW_TEST data as a curve. If you now want to export this curve, e.g. as PDF, you can use the script Create Reports.

For further details have a look at the code documentation above or look at the JAVADOC of jBEAM.


Copyright by Kistler Chemnitz GmbH 2021
XWiki Enterprise 4.4 - Documentation