You can create a basic two-dimensional representation of data with just a GraphElement object. To represent additional dimensions by using other visual attributes of elements, create a VisualFrame.
To understand how to use a VisualFrame, consider the script below (Note: Report script that modifies 'graph' should be placed at the element level. See Adding Element-Level Script)
importPackage(inetsoft.graph): importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) var arr = [["State","Quantity","Total"], ["NJ",200,2500],["NY",300,1500]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new PointElement("State", "Quantity"); graph.addElement(elem);
This creates a basic point (scatter) chart displaying the dimensions 'State' and 'Quantity'. If you want to additionally represent the dimension 'Total' with the element size, use a VisualFrame such as the LinearSizeFrame. Follow these steps:
var frame = new LinearSizeFrame(); frame.setField("Total");
A VisualFrame object such as LinearSizeFrame contains a mapping between data values and physical attributes. Therefore, you need a Scale to specify the mapping's scaling.
var scale = new LinearScale(); scale.setFields("Total"); scale.setMax(3000); scale.setMin(1000);
frame.setScale(scale);
elem.setSizeFrame(frame);
The point sizes now represent the data values contained in the 'Total' field. The complete script is shown below.
importPackage(inetsoft.graph) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) var arr = [["State","Quantity","Total"], ["NJ",200,2500],["NY",300,1500]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new PointElement("State", "Quantity"); var frame = new LinearSizeFrame(); frame.setField("Total"); var scale = new LinearScale(); scale.setFields("Total"); scale.setMax(3000); scale.setMin(1000); frame.setScale(scale); elem.setSizeFrame(frame); graph.addElement(elem);
Copyright © 2024, InetSoft Technology Corp.