To alter the appearance of chart axes, use the Chart's setScale() method to assign a new Scale object. For example, you can replace a linear scale with a logarithmic scale, show or hide tick marks, display axis labels at top or right, change the label font and color, etc. Consider the following example:
#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index | Read More |
importPackage(inetsoft.graph) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.data) var arr = [["State","Quantity"], ["NJ",200], ["NY",3000]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new IntervalElement("State", "Quantity"); graph.addElement(elem);This creates a basic bar chart displaying the dimensions 'State' and 'Quantity'.
Follow the steps below to experiment with modifying the chart's axes:
var logscale = new LogScale('Quantity');
var yspec = new AxisSpec(); yspec.setLineColor(java.awt.Color(0x0000ff)); yspec.setGridColor(java.awt.Color(0x0000ff)); yspec.setGridStyle(GraphConstants.DOT_LINE); logscale.setAxisSpec(yspec);
var cscale = new CategoricalScale('State');
var xspec = new AxisSpec(); xspec.setLineVisible(false); xspec.setTickVisible(false); cscale.setAxisSpec(xspec);
var tspec = new TextSpec(); tspec.setFont(java.awt.Font('Dialog', java.awt.Font.BOLD, 14)); xspec.setTextSpec(tspec); xspec.setAxisStyle(AxisSpec.AXIS_SINGLE2);
var tframe = new DefaultTextFrame(); tframe.setText('NJ','New Jersey'); tframe.setText('NY','New York'); xspec.setTextFrame(tframe);
graph.setScale('Quantity',logscale); graph.setScale('State',cscale);
The complete script is shown below:
importPackage(inetsoft.graph) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.data) var arr = [["State","Quantity"], ["NJ",200], ["NY",3000]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new IntervalElement("State", "Quantity"); var logscale = new LogScale('Quantity'); var yspec = new AxisSpec(); yspec.setLineColor(java.awt.Color(0x0000ff)); yspec.setGridColor(java.awt.Color(0x0000ff)); yspec.setGridStyle(GraphConstants.DOT_LINE); logscale.setAxisSpec(yspec); var cscale = new CategoricalScale('State'); var xspec = new AxisSpec(); xspec.setLineVisible(false); xspec.setTickVisible(false); cscale.setAxisSpec(xspec); var tspec = new TextSpec(); tspec.setFont(java.awt.Font('Dialog', java.awt.Font.BOLD, 14)); xspec.setTextSpec(tspec); xspec.setAxisStyle(AxisSpec.AXIS_SINGLE2); var tframe = new DefaultTextFrame(); tframe.setText('NJ','New Jersey'); tframe.setText('NY','New York'); xspec.setTextFrame(tframe); graph.setScale('Quantity',logscale); graph.setScale('State',cscale); graph.addElement(elem);
![]() |
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software. |
Previous: Changing the Appearance of a Dashboard Chart |
Next: Dashboarding API
|