<%@ page import = "com.gp.api.jsp.MxServerComponent" %>
<%@ page import = "com.gp.api.jsp.MxChartDescription"%>
<%@ page import = "com.gp.api.model.MxStandardChartModel"%>
<table><tr><td>
<%!
private static MxStandardChartModel getDefaultChartModel() {
MxStandardChartModel model = new MxStandardChartModel();
// Define model's columns. You need to define rows prior to inserting columns (or vice a versa),
// since the number of the rows in the inserted column is clipped to the number of the rows.
model.insertRow("Income",null,-1);
model.insertRow("Expense", null,-1);
double v2001[] = { 1000,-800 };
double v2002[] = { 1020,-810 };
double v2003[] = { 1100,-880 };
double v2004[] = { 1190,-920 };
// insert rows into the model
model.insertCol("2001", v2001,-1);
model.insertCol("2002", v2002,-1);
model.insertCol("2003", v2003,-1);
model.insertCol("2004", v2004,-1);
return model ;
}
%>
<%
// Create and polulate model object
String modelXML = request.getParameter("modelXML");
MxStandardChartModel model = modelXML == null ? getDefaultChartModel() : (MxStandardChartModel) MxStandardChartModel.fromXML(modelXML, null);
String showNET = request.getParameter("showNET");
if("on".equalsIgnoreCase(showNET)) {
if(model.getRowCount() == 2) {
// We need to insert a new row with NET values
double values [] = new double[model.getColCount()];
for(int i=0;i<values.length;i++)
values[i] = model.getValueAt(0,i) + model.getValueAt(1,i);
model.insertRow("NET", values, -1) ;
}
} else {
if(model.getRowCount() == 3) // Remove NET row
model.deleteRow(2);
}
// Create and display the chart
MxServerComponent svr = MxServerComponent.getDefaultInstance(application);
MxChartDescription myChart = svr.newImageSpec();
myChart.width = 320 ;
myChart.height= 300 ;
myChart.type = "PNG" ;
myChart.style = " <frameChart is3D=\"false\"> <frame isHStripVisible=\"true\" stripColor=\"#40CCAAEE\"/> <xAxis isAntialiased=\"true\"> <labelFormat pattern=\"#,##0.###\"/> <parseFormat pattern=\"#,##0.###\"/><titleStyle font=\"Arial-12-bold\">Year </titleStyle> </xAxis> <yAxis scaleMin=\"0\" isAntialiased=\"true\"> <labelFormat pattern=\"#,##0.###\"/> <parseFormat pattern=\"#,##0.###\"/> <titleStyle margin=\"4\" font=\"Arial-12-bold\"> <![CDATA[ Sales ('000) ]]> </titleStyle> </yAxis> <legend spacing=\"0\" halign=\"Right\" isAntialiased=\"true\"> <decoration style=\"None\"/> </legend> <elements drawShadow=\"true\"> <morph morph=\"Grow\"/> </elements> <popup background=\"#CCFFFF\" isAntialiased=\"true\" foreground=\"black\"/> <paint isVertical=\"true\" min=\"47\" max=\"83\"/> </frameChart>" ;
myChart.model = model.toXML();
out.write(svr.getImageTag(myChart,"getimage.jsp?image="));
%>
</td><td width=20></td><td valign=top style="font-family:Arial; font-size:10pt">
<form name=ModelForm id=ModelForm method="POST">
<input type=hidden name="modelXML" value="<%=myChart.model.replace('"', '\'') %>">
<p>Check or uncheck "Show NET" radio button to show/hide the additional NET series:
<p>
<input type=checkbox name=showNET onclick="javascript:document.ModelForm.submit()" <%="on".equalsIgnoreCase(showNET) ? "checked" : ""%>>Show NET
</form>
</td></tr></table>
|