Changing Chart Scaling
A Scale object determines how abstract data values are mapped to physical chart representations such as position, color, shape, etc. The EGraph object and the VisualFrame object both map data values to physical representations, so both of these objects require a Scale.
Changing Scaling for Chart Axes
See Also Changing Axis Properties, for examples of other axis modifications. To change the scaling of chart axes, simply assign a new Scale to the Chart object. For example, consider the following chart:
importPackage(inetsoft.graph)
importPackage(inetsoft.graph.data)
importPackage(inetsoft.graph.element)
importPackage(inetsoft.graph.scale)
var arr = [["State","Quantity"], ["CA",200], ["NY",3000]];
dataset = DefaultDataSet(arr) graph = new EGraph();
var elem = new IntervalElement("State", "Quantity");
graph.addElement(elem);
#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index |
|
Read More |
Note that in this chart the IntervalElement object implicitly defines a linear Y-axis scale. However, the data values on the chart are widely different in magnitude, which suggests that a log scale might be more appropriate.
To change the Y-axis to use a log scale, follow these steps:
1. Define the desired Scale object explicitly. In this case, create a LogScale based on the 'Quantity' field.
var scale = new LogScale("Quantity");
2. Assign the new scale to the Y-axis of the chart object using the setScale() method.
graph.setScale("Quantity",scale); The complete script with the new chart scaling looks like this:
importPackage(inetsoft.graph)
importPackage(inetsoft.graph.element)
importPackage(inetsoft.graph.scale)
importPackage(inetsoft.graph.data)
var arr = [["State","Quantity"], ["CA",200], ["NY",3000]];
dataset = new DefaultDataSet(arr);
graph = new EGraph();
var elem = new IntervalElement("State", "Quantity");
var scale = new LogScale("Quantity");
graph.addElement(elem);
graph.setScale("Quantity",scale);