Focal Point
[SHARING] Format JSCHART events

This topic can be found at:
http://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8317005486

November 06, 2016, 10:31 PM
Waz
[SHARING] Format JSCHART events
If you were not aware, there are events available on jscharts.

There is a small technique to turn them on.

The code between *GRAPH_JS and *END adds an event to an object on the chart. I haven't investigated all the objects, and some are difficult to track down, but the main ones are there.

We have have implemented this for some of our jscharts to add extra functionality.

Hope someone finds this useful.

A simple example is below that highlights the events and what is available. There is much more if you check the js objects passed into the functions.

-DEFAULTH &WF_STYLE_UNITS='PIXELS';
-DEFAULTH &WF_STYLE_HEIGHT='405.0';
-DEFAULTH &WF_STYLE_WIDTH='770.0';

-*SET JSURL = '{jsfile}'

-HTMLFORM BEGIN
<!doctype html>
<html lang="en">
	<head>
		<title>Chart Events</title>
		<script type="text/javascript">
			<!--
				function chartEvent(chtObj) {
					if (validName(chtObj.chartObjName))  return ;

					var clickText = chtObj.chartObjName ;
					console.log(chtObj)
					if (typeof chtObj.group != 'undefined') clickText += ' (Group: ' + chtObj.group + ')' ;
					if (typeof chtObj.series != 'undefined') clickText += ' (Series: ' + chtObj.series + ')' ;
					if (typeof chtObj.svgElement != 'undefined') {
						if (chtObj.svgElement.innerHTML.length > 0) clickText += ' (' + chtObj.svgElement.innerHTML + ')' ;
					}
					document.getElementById(chtObj.event.type + 'Evt').innerHTML = clickText ;
				}
				function validName(name) {
					if (name=='legendPanel') return true ;
					return false ;
				}
			//-->
		</script>
	</head>
	<body>
		<table>
			<tr>
				<td>Click Event:</td>
				<td><div id="clickEvt"></div></td>
			</tr>
			<tr>
				<td>Mouse Over Event:</td>
				<td><div id="mouseoverEvt"></div></td>
			</tr>
			<tr>
				<td>Mouse Out Event:</td>
				<td><div id="mouseoutEvt"></div></td>
			</tr>
		</table>
	</body>
</html>
-HTMLFORM END


GRAPH FILE car
-* Created by Info Assist for Graph
SUM CAR.BODY.DEALER_COST
CAR.BODY.SALES
CAR.BODY.RETAIL_COST
CAR.BODY.SEATS
BY CAR.ORIGIN.COUNTRY
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET HTMLENCODE ON
ON GRAPH SET GRAPHDEFAULT OFF
ON GRAPH SET GRWIDTH 1
ON GRAPH SET UNITS &WF_STYLE_UNITS
ON GRAPH SET HAXIS &WF_STYLE_WIDTH
ON GRAPH SET VAXIS &WF_STYLE_HEIGHT
ON GRAPH SET GRMERGE ADVANCED
ON GRAPH SET GRMULTIGRAPH 0
ON GRAPH SET GRLEGEND 0
ON GRAPH SET GRXAXIS 1
ON GRAPH SET LOOKGRAPH VBAR2AX
-*ON GRAPH SET AUTOFIT ON
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setTitleString("Chart Title");
setSubtitleString("Chart Sub-Title");
setFootnoteString("Chart Footnote");
setY1TitleString("Y1Title");
setY2TitleString("Y2Title");
setO1TitleString("O1Title");
setAxisAssignment(3,1);
setSeriesType(getSeries(3),2);
-*setDisplay(getAnnotation(0), true);
-*setTextString(getAnnotation(0), "annotation0");
-*setRect(getAnnotation(0),new Rectangle(-15340,13000,29850,1800));
-*setDisplay(getAnnotation(1), true);
-*setTextString(getAnnotation(1), "annotation1");
-*setRect(getAnnotation(1),new Rectangle(15340,13000,29850,1800));
-*setDisplay(getReferenceLineY1(0),true);
-*setReferenceLineValueY1(0,80000.0);
-*setLineWidth(getReferenceLineY1(0),2);
*END
*GRAPH_JS
});
chart.registerEvent(chartEvent, 'click', 'background');
chart.registerEvent(chartEvent, 'mouseover', 'background');
chart.registerEvent(chartEvent, 'mouseout', 'background');
chart.registerEvent(chartEvent, 'click', 'xaxis');
chart.registerEvent(chartEvent, 'mouseover', 'xaxis');
chart.registerEvent(chartEvent, 'mouseout', 'xaxis');
chart.registerEvent(chartEvent, 'click', 'yaxis');
chart.registerEvent(chartEvent, 'mouseover', 'yaxis');
chart.registerEvent(chartEvent, 'mouseout', 'yaxis');
chart.registerEvent(chartEvent, 'click', 'y2axis');
chart.registerEvent(chartEvent, 'mouseover', 'y2axis');
chart.registerEvent(chartEvent, 'mouseout', 'y2axis');
chart.registerEvent(chartEvent, 'click', 'legend');
chart.registerEvent(chartEvent, 'mouseover', 'legend');
chart.registerEvent(chartEvent, 'mouseout', 'legend');
chart.registerEvent(chartEvent, 'click', 'title');
chart.registerEvent(chartEvent, 'mouseover', 'title');
chart.registerEvent(chartEvent, 'mouseout', 'title');
chart.registerEvent(chartEvent, 'click', 'subtitle');
chart.registerEvent(chartEvent, 'mouseover', 'subtitle');
chart.registerEvent(chartEvent, 'mouseout', 'subtitle');
chart.registerEvent(chartEvent, 'click', 'series');
chart.registerEvent(chartEvent, 'mouseover', 'series');
chart.registerEvent(chartEvent, 'mouseout', 'series');
chart.registerEvent(chartEvent, 'click', 'footnote');
chart.registerEvent(chartEvent, 'mouseover', 'footnote');
chart.registerEvent(chartEvent, 'mouseout', 'footnote');
-*chart.registerEvent(chartEvent, 'click', 'annotation');
-*chart.registerEvent(chartEvent, 'mouseover', 'annotation');
-*chart.registerEvent(chartEvent, 'mouseout', 'annotation');
-*chart.registerEvent(chartEvent, 'click', 'reference');
-*chart.registerEvent(chartEvent, 'mouseover', 'reference');
-*chart.registerEvent(chartEvent, 'mouseout', 'reference');
-*chart.registerEvent(chartEvent, 'click', 'chart');
-*chart.registerEvent(chartEvent, 'mouseover', 'chart');
-*chart.registerEvent(chartEvent, 'mouseout', 'chart');

chart.set({
*END

INCLUDE=IBFS:/FILE/IBI_HTML_DIR/javaassist/intl/EN/ENIADefault_combine.sty,$
TYPE=REPORT, TITLETEXT=JSCHART Events, $
ENDSTYLE
END
-RUN



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

November 07, 2016, 05:45 AM
Tony A
Nice, now where's the like button? Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
November 07, 2016, 06:18 AM
Neelima
Cool..


WebFocus 8104,8204
Excel/PDF/HTML/HTMLTABLE/XML/ALPHA/GIF file/GRAPH/Active technologies
November 07, 2016, 10:59 AM
Francis Mariani



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
November 10, 2016, 02:45 PM
CoolGuy
Nice! Thanks for sharing!


8.2.02M (production), 8.2.02M (test), Windows 10, all outputs.