NetCharts® Pro: JavaScriptRepository.java
(A Helper Application for the DrillDownExample)
The complete source code:
package ncpro.examples.servlet.drilldown;
/*
JavaScriptRepository
Visual Mining, Inc.Will return JavaScript code to include within the returned HTML.
This JavaScript will give the ability to show "rollover" active labels.
*/public class JavaScriptRepository {
public JavaScriptRepository() {
}public String getJavaScript(String mapName) {
String javaScript = "<div id=\"popuplabel\" align=\"center\" style=\"position:absolute; visibility:hidden; width:auto;\"></div>\n" +
"<script language=\"JavaScript\">\n" +
"<!--\n" +
"function Is()\n" +
"{\n" +
"this.ver=navigator.appVersion\n" +
"this.agent=navigator.userAgent.toLowerCase()\n" +
"this.dom=document.getElementById?1:0\n" +
"this.opera5=(navigator.userAgent.indexOf(\"opera\")>-1 && document.getElementById)?1:0\n" +
"this.ie4=(document.all && !this.dom && !this.opera5)?1:0;\n" +
"this.ie5=(this.ver.indexOf(\"msie 5\")>-1 && this.dom && !this.opera5)?1:0;\n" +
"this.ie6=(this.ver.indexOf(\"msie 6\")>-1 && this.dom && !this.opera5)?1:0;\n" +
"this.ie=(this.agent.indexOf(\"msie\") != -1)\n" +
"this.mac=this.agent.indexOf(\"max\")>-1\n" +
"this.nav=((this.agent.indexOf(\"mozilla\")!=-1) && ((this.agent.indexOf(\"spoofer\")==-1) && (this.agent.indexOf(\"compatible\") == -1)))\n" +
"this.nav5up=(this.dom && parseInt(this.ver) >= 5) ?1:0;\n" +
"this.nav4=(document.layers && !this.dom)?1:0;\n" +
"return this\n" +
"}\n" +
"if(!is) { var is = new Is(); }\n" +
"var font = \"Lucida Console\";\n" +
"var fontsize = \"8\";\n" +
"var fontcolor = \"#000000\";\n" +
"var dwellbgcolor = \"#FFFFE1\";\n" +
"if(!begin) { var begin = new Array(); }\n" +
"if(!end) { var end = new Array(); }\n" +
"begin[\"" + mapName + "\"]='<table '+(dwellbgcolor.length==0 ? '' : 'bgcolor=\"'+dwellbgcolor+'\"')+' border=0 cellpadding=0 cellspacing=0 align=\"left\"> <tr> <td align=\"center\" valign=\"middle\" style=\"border-style: solid; border-width: 1; padding-left: 1; padding-right: 1\" bordercolor=\"#000000\"> <span style=\"font-family: '+font+'; font-size: '+fontsize+'pt; color: '+fontcolor+';\">';\n" +
"end[\"" + mapName + "\"]='</span> </td> </tr> </table>';\n" +"Xoffset=5; // modify these values to ...\n" +
"Yoffset=20; // change the popup position.\n" +"var skn;\n" +
"var yyy=-1000;\n" +
"var timeoutID = null;\n" +"if (is.nav4)\n" +
"skn=document.popuplabel;\n" +
"else if (is.nav5up)\n" +
"skn=document.getElementById(\"popuplabel\").style;\n" +
"else if (is.ie)\n" +
"skn=document.all.popuplabel.style;\n" +"if(is.nav4)\n" +
"{\n" +
"document.captureEvents(Event.MOUSEMOVE);\n" +
"document.onmousemove=get_mouse; \n" +
"}\n" +
"else \n" +
"{\n" +
"if (is.nav5up)\n" +
"{\n" +
"document.addEventListener(\"mousemove\", get_mouse, true);\n" +
"}\n" +
"else\n" +
"{\n" +
"document.onmousemove=get_mouse;\n" +
"}\n" +
"skn.visibility=\"visible\";\n" +
"skn.display=\"none\";\n" +
"}\n" +"function displayActiveLabel(which, text)\n" +
"{\n" +
"var content = begin[which]+text+end[which]\n" +
"yyy=Yoffset;\n" +
"if(is.ie)\n" +
"{\n" +
"document.all(\"popuplabel\").innerHTML=content;\n" +
"skn.display='';\n" +
"}\n" +
"else if(is.nav4)\n" +
"{\n" +
"skn.document.write(content);\n" +
"skn.document.close();\n" +
"skn.visibility=\"visible\";\n" +
"}\n" +
"else if(is.nav5up)\n" +
"{\n" +
"document.getElementById(\"popuplabel\").innerHTML=content;\n" +
"skn.display='';\n" +
"skn.visibility=\"visible\";\n" +
"}\n" +
"window.status = text;\n" +
"timeoutID = setTimeout(\"window.status = unescape('\"+escape(text)+\"');\", 0);\n" +
"}\n" +"function get_mouse(e)\n" +
"{\n" +
"if (is.nav4)\n" +
"{\n" +
"skn.x = e.pageX+Xoffset-(skn.document.width/2);\n" +
"}\n" +
"else if (is.ie)\n" +
"{\n" +
"skn.pixelLeft = event.x+document.body.scrollLeft+Xoffset-(document.all(\"popuplabel\").clientWidth/2);\n" +
"}\n" +
"else if (is.nav5up)\n" +
"{\n" +
"var x = e.clientX;\n" +
"var layr = document.getElementById(\"popuplabel\");\n" +
"var dX = parseInt(document.defaultView.getComputedStyle(layr,'').getPropertyValue('width'))/2;\n" +
"skn.left = x-dX;\n" +
"}\n" +
"var y=(is.nav4||is.nav5up)?e.pageY:event.y+document.body.scrollTop;\n" +
"skn.top=y+yyy;\n" +
"}\n" +"function unDisplayActiveLabel()\n" +
"{\n" +
"yyy=-1000;\n" +
"if(is.nav4)\n" +
"{\n" +
"skn.visibility=\"hidden\";\n" +
"}\n" +
"else if (is.nav5up||is.ie)\n" +
"{\n" +
"skn.display=\"none\";\n" +
"}\n" +
"window.status = \"\";\n" +
"clearTimeout(timeoutID);\n" +
"}\n" +"//-->\n" +
"</script>\n";
return javaScript;
}
}
// Create the Active Labels.
NFVector activeLabels = new NFVector();
activeLabels.addElement (new NFActiveLabel("", "", ""));
activeLabels.addElement (new NFActiveLabel("", "", ""));
set.setActiveLabels(activeLabels);// Set the BarSeries of the chart.
bs.setElementAt(set, 0);
chart.setBarSeries(bs);// Create the Bar Labels.
NFVector barLabels = new NFVector();
barLabels.addElement ("Audio");
barLabels.addElement ("Video");
chart.setDataLabels(barLabels);// Create the Active Labels for the Bars.
NFVector activeLabel1 = new NFVector();
activeLabel1.addElement (new NFActiveLabel("Audio", "", ""));
activeLabel1.addElement (new NFActiveLabel("Video", "", ""));
chart.setBarActiveLabels(activeLabel1);// Set the values for the Footer.
NFTitle footer = chart.getFooter();
NFActiveLabel footerAL = footer.getActiveLabel();
footerAL.setLabel("Go Back");
footerAL.setURL(servletName + "?year=" + year + "®ion=" + region + "&city=" + city + "&goback=true");
footer.setActiveLabel(footerAL);
chart.setFooter(footer);// Set the Top Axis Title Label.
NFAxis topAxis = chart.getTopAxis();
NFLabel topLabel = topAxis.getTitleLabel();
topLabel.setText(year + " " + city + " Sales by Category");
topAxis.setTitleLabel(topLabel);
chart.setTopAxis(topAxis);// Set the Right Axis Title Label.
NFAxis rightAxis = chart.getRightAxis();
NFLabel rightLabel = rightAxis.getTitleLabel();
rightLabel.setText(" ");
rightAxis.setTitleLabel(rightLabel);
chart.setRightAxis(rightAxis);// Set the Left Scale.
NFAxisRange leftScale = new NFAxisRange(0, 90000, 9000);
NFAxis leftAxis = chart.getLeftAxis();
leftAxis.setScale(leftScale);
chart.setLeftAxis(leftAxis);
} catch (Exception e) {
// Perform error handling
System.out.println(e);
}
}
}
![]()



