<%// ChangeBarWidth:%>
<%
// A graph's display properties (bar width, orientation, axis characteristics,
// and so on) are general properties that are defined in the graph's model.
// Thus, to change the width of bar elements,
// 1) Get the BarChart's graph model
// 2) Call setGrowBarWidthEnabled() to set the boolean to true
// 3) Call setBarWidth() to set a width for the bars
%>
<%@page import="
com.sas.servlet.tbeans.graphics.html.BarChart,
com.sas.graphics.components.barchart.BarChartModel,
com.sas.graphics.components.barchart.BarChartTableDataModel,
com.sas.measures.BaseLength,
com.sas.graphics.components.AnalysisVariable,
com.sas.graphics.components.ClassificationVariable,
com.sas.swing.models.TableModelAdapter,
com.sas.models.SimpleTable,
java.awt.Color"
%>
<%
// Create a BarChart instance
BarChart barChart = new BarChart();
// Create a simple SAS table and add data to it
SimpleTable table = new SimpleTable();
%>
<%@ include file="EnergyData.jsp" %>
<%
// Convert a simple SAS table to a simple Java Swing table
TableModelAdapter tma = new TableModelAdapter(table);
tma.setFormattedDataUsed(false);
// Create a data model and attach the data source
BarChartTableDataModel dataModel=
new BarChartTableDataModel(tma);
// Assign the data model to the BarChart
barChart.setDataModel(dataModel);
// 1) Get the BarChart's graph model
BarChartModel graphModel=barChart.getGraphModel();
// 2) Call setGrowBarWidthEnabled() to set the boolean to true
graphModel.setGrowBarWidthEnabled(true);
// 3) Call setBarWidth() to set a width for the bars
graphModel.setBarWidth(new BaseLength("0.75in"));
// Assign the Category variable role, and optionally the
// Response variable role, to appropriate variable(s)
dataModel.setCategoryVariable(
new ClassificationVariable("EnergyType"));
dataModel.setResponseVariable(
new AnalysisVariable("Produced"));
// Set a graph title
barChart.getTitle1().setText("Energy Production");
// Set HTTP-specific response and request functionality
barChart.setResponse(response);
barChart.setRequest(request);
// Write the chart to the display
barChart.write(out);
%>