CT.7.1 Changing Scaling for Chart Axes
To change the scaling of chart axes, simply assign a new Scale to the Chart object. For example, consider the following chart:
Note: Script that modifies 'graph' should be placed at the element level. See Adding Element-Level Script in Report Scripting and Adding Component Script in Dashboard Scripting for more information.
dataset = [["State","Quantity"], ["CA",200], ["NY",3000]];
graph = new EGraph();
var elem = new IntervalElement("State", "Quantity");
graph.addElement(elem);

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:
dataset = [["State","Quantity"], ["CA",200], ["NY",3000]];
graph = new EGraph();
var elem = new IntervalElement("State", "Quantity");
var scale = new LogScale("Quantity");
graph.addElement(elem);
graph.setScale("Quantity",scale);

In this example (for Viewsheets), you will dynamically modify the axis range to match the data displayed on the chart. In particular, you will adapt the lower limit on the Y-axis so that it is always 75% of the lowest data value shown on the chart.
Follow the steps below:
1. Create a new Viewsheet based on the 'Sales' > 'Sales Explore' Worksheet.
2. Add a Chart component to the Viewsheet, and click the center of the chart to open the Chart Editor.
3. From the 'Dimensions' node of the 'Data Source' panel, drag the 'State' field to the 'X' region of the 'Data' panel.
4. From the 'Measures' node of the 'Data Source' panel, drag the 'Total' field to the 'Y' region of the 'Data' panel.
5. Click the 'Edit Dimension' button next to the 'State' field in the 'Data' panel.

6. From the 'Ranking' option in the 'Edit Dimension' panel, specify 'Top 5 of Sum(Total)'. Click the 'Apply' button.

7. Right-click the Chart component on the Viewsheet grid, and select 'Properties' from the context menu. This opens the 'Chart Properties' dialog box.
Note: To access the data prior to chart aggregation, see Accessing Worksheet Data in Dashboard Scripting.
8. Select the Script tab, and enter the following script:
var dMin = 10000000; // Default minimum
// Get a handle to the chart's Y-axis Scale:
var yScale = graph.getCoordinate().getYScale();
// Find the minimum Y-value in the chart data:
for (var i=0; i<dataset.getRowCount(); i++) {
yVal = dataset.getData('Sum(Total)',i);
if(yVal < dMin) {
dMin = yVal;
}
}
// Set Y-axis lower limit to .75 of minimum value:
yScale.setMin(.75*dMin);
9. Click the 'OK' button to close the 'Chart Properties' dialog box. Observe how the chart Y-axis updates so that the lower limit is 75% of the smallest chart value.

10. From the 'Data Source' panel of the Chart Editor, drag the 'Category' field onto the Viewsheet grid. This creates a 'Category' selection list.

11. Select different combinations of categories from the 'Category' selection list, and observe how the chart axis updates.
See Also
Changing Axis Properties, for examples of other axis modifications.
| << CT.7 Changing Chart Scaling | © 1996-2013 InetSoft Technology Corporation (v11.4) | CT.7.2 Changing Scaling for a VisualFrame >> |