<html>
	<head>
		<title>Event Markers Events Handling</title>
		<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
		<!--- 
			This sample uses jquery library to work with DOM  
		-->
		<script type="text/javascript" language="javascript" src="./js/jquery.min.js"></script>
		<script type="text/javascript" language="javascript" src="./../js/AnyChartStock.js?v=1.9.0r9317"></script>
		<!-- chart size settings -->
		<style type="text/css">
			#chartContainer {
				width: 700px;
				height: 550px;
			}
		</style>
		<script type="text/javascript" language="javascript">
			// Creating new chart object. 
			var chart = new AnyChartStock("./../swf/AnyChartStock.swf?v=1.9.0r9317", "./../swf/Preloader.swf?v=1.9.0r9317");
			// Setting XML config file.
			chart.setXMLFile("config.xml");
			// Background color
			chart.bgColor = "#F8F4F0";
			// wmode is set to opaque to show HTML tooltip above the chart
			chart.wMode = "opaque";
			// Writing the flash object into the page DOM.
			chart.write("chartContainer");
			
			//--------------------------------------------------------------------------------
			//		Event Markers Events handling
			//--------------------------------------------------------------------------------
			
			// event marker mouse over
			chart.onEventMarkerMouseOver = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerMouseOver", eventMarkerInfo);
				showTooltip(eventMarkerInfo);
			};
			
			// event marker mouse out
			chart.onEventMarkerMouseOut = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerMouseOut", eventMarkerInfo);
				hideTooltip();
			};
			
			// event marker click
			chart.onEventMarkerClick = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerClick", eventMarkerInfo);
			};
			
			// event marker double click
			chart.onEventMarkerDoubleClick = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerDoubleClick", eventMarkerInfo);
			};
			
			// event marker select
			chart.onEventMarkerSelect = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerSelect", eventMarkerInfo);
			};
			
			// event marker deselect
			chart.onEventMarkerDeselect = function(eventMarkerInfo) {
				showEventInfo("onEventMarkerDeselect", eventMarkerInfo);
			};
			
			//--------------------------------------------------------------------------------
			//		Tooltip
			//--------------------------------------------------------------------------------
			
			// Tooltip Show Function
			function showTooltip(info) {
				var tooltip = $("#tooltip");
				
				var offset = $(chart.target).offset();
				
				// Right bottom of event marker 
				var x = info.bounds.x + info.bounds.width;
				var y = info.bounds.y + info.bounds.height;
            	
				// Add mouse offset 
				offset.left += x;
				offset.top += y;
            
				// Update tooltip position
				tooltip.css("left",offset.left+"px");
				tooltip.css("top",offset.top+"px");

				// Update tooltip text
				tooltip.html("HTML page coords: { x:"+offset.left+", y:"+offset.top+" }<br />"+
							 "Flash player coords: { x:" + x + ", y:" + y + " }");
				tooltip.css("display","block");
			}
			
			// Hide tooltip function
			function hideTooltip() {
				$("#tooltip").css("display","none");				
			}
			
			//--------------------------------------------------------------------------------
			//		Auxiliary Functions
			//--------------------------------------------------------------------------------
			
			// Date time formatting.
			// Mask: %yyyy-%MM-%dd
			function getFormattedDate(date) {
				var month = (date.getUTCMonth() + 1 < 10) ? "0" + (date.getUTCMonth() + 1) : (date.getUTCMonth() + 1);
				var dt = (date.getUTCDate() < 10) ? "0" + date.getUTCDate() : date.getUTCDate();
				return date.getUTCFullYear() + "-" + month + "-" + dt;
			}
			
			// Event Logging Function
			function showEventInfo(type, eventMarkerInfo) {
				showEventDetails(type, eventMarkerInfo);
				logEvent(type, eventMarkerInfo);
			}
			
			// Events Log
			var events = [];
			
			function logEvent(type, info) {
				// Show only ten last events
				events.push({type: type, id:info.id});
				if (events.length > 10)
					events = events.splice(1);
				
				// Events are shown in log table
				for (var i = 0;i<events.length;i++) {
					var e = events[events.length-1-i];
					var rowIndex = (i+2).toString();
					
					var row = $("table.log tr:eq("+rowIndex+")");

					row.find("td:eq(0)").html(e.type);
					row.find("td:eq(1)").html(e.id);
				}
			}
			
			// Full event information
			function showEventDetails(type, info) {
				$("#detailsFieldEventType").html(type); // Event type
				$("#detailsFieldId").html(info.id); // id of the event marker that fires the event
				$("#detailsFieldGroupId").html(info.groupId); // id of the event markers group
				$("#detailsFieldChartId").html(info.chartId); // id of the chart
				$("#detailsFieldSeriesId").html(info.seriesId); // id of the series, to which marker is bound
				$("#detailsFieldDate").html(getFormattedDate(info.date)); // Date
				$("#detailsFieldGroupedDate").html(getFormattedDate(info.groupedDate)); // Date after grouping (if any)
				// Pixel coordinates and size of event marker
				$("#detailsFieldBoundsX").html(Math.round(info.bounds.x*100)/100);
				$("#detailsFieldBoundsY").html(Math.round(info.bounds.y*100)/100);
				$("#detailsFieldBoundsWidth").html(Math.round(info.bounds.width*100)/100);
				$("#detailsFieldBoundsHeight").html(Math.round(info.bounds.height*100)/100);
				
				// Custom attributes 
				$("table.details tr.attr").remove();
				// info.customAttributes - Object. key - custom attribute name, value - custom attribute value
				for (var j in info.customAttributes) {
					// Add custom attributes information to the end of the table
					$("table.details tr:last").after("<tr class='attr'>"+
						"<td>"+j+"</td>"+
						"<td>"+info.customAttributes[j]+"</td>"+
					"</tr>");
				}
			}
			
		</script>
		<!-- Log table style, tooltip style and other -->
		<style type="text/css">
			table.settings  {
				border-style: solid;
				border-width: 1px;
				border-color: #D0CDC9;
			}

			table.settings tr th {
				font:normal 7pt Verdana;
				background-color: #DCD9D5;
				font-weight:bold;
				padding-bottom:5px;
				padding-top:5px;
				padding-left:10px;
				text-align:left;
			}
			table.settings tr td {
				background-color: #F8F4F0;
				font:normal 8pt Verdana;
				padding-bottom:2px;
				padding-top:2px;
				padding-left:10px;
				text-align:left;	
			}
			td.log {
				height: 18px;
			}
			
			#tooltip {
				position: absolute; /* This parameter is required to position tooltip properly */
				left: 0;
				top: 0;
				
				border: 1px solid #505050;
				background-color: White;
				display: block;
				padding: 5px;
				font-size: 9px;
				font-family: Verdana;
				font-weight: bold;
				
				color: #333333;
				line-height: 13px;
				
				display: none;
			}
			
			table.settings tr td.offset {
				text-align: center;
				vertical-align: middle;
				font-weight: bold;
				border: 0;
			}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td>
					<table class="settings">
						<tr>
						  <th colspan="3">Move the mouse over any of the event markers to see events they fire:</th>
						</tr>
						<tr><td colspan="2"></td><td class="offset">(OFFSET TOP)<br /><img src="offset_top_icon.png" alt="top offset" /></td></tr>
						<tr><td class="offset">(OFFSET LEFT)</td><td class="offset"><img src="offset_left_icon.png" alt="left offset"/></td>
                        <td id="chartContainer"><!-- Chart Container --></td></tr>
					</table>
				</td>
				<td valign="top">
					<table>
						<tr>
							<td width="320">
							<!-- events log -->
							<table class="settings log" width="100%">
								<tr><th colspan="2">Events Log:</th></tr>
								<tr><th width="200">Mouse event</th><th>Event marker id</th></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
								<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<!-- event info -->
							<table class="settings details" width="100%">
								<tr><th colspan="2">Mouse event details:</th></tr>
								<tr>
									<td width="110">Mouse Event Type:</td>
									<td id="detailsFieldEventType">&nbsp;</td>
								</tr>
								<tr>
									<td>id</td>
									<td id="detailsFieldId">&nbsp;</td>
								</tr>
								<tr>
									<td>chartId</td>
									<td id="detailsFieldChartId">&nbsp;</td>
								</tr>
								<tr>
									<td>seriesId</td>
									<td id="detailsFieldSeriesId">&nbsp;</td>
								</tr>
								<tr>
									<td>groupId</td>
									<td id="detailsFieldGroupId">&nbsp;</td>
								</tr>
								<tr>
									<td>date</td>
									<td id="detailsFieldDate">&nbsp;</td>
								</tr>
								<tr>
									<td>groupedDate</td>
									<td id="detailsFieldGroupedDate">&nbsp;</td>
								</tr>
								<tr>
									<td>bounds.x</td>
									<td id="detailsFieldBoundsX">&nbsp;</td>
								</tr>
								<tr>
									<td>bounds.y</td>
									<td id="detailsFieldBoundsY">&nbsp;</td>
								</tr>
								<tr>
									<td>bounds.width</td>
									<td id="detailsFieldBoundsWidth">&nbsp;</td>
								</tr>
								<tr>
									<td>bounds.height</td>
									<td id="detailsFieldBoundsHeight">&nbsp;</td>
								</tr>
								<tr>
									<th colspan="2">Custom attributes:</th>
								</tr>
							</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		
		<!-- 
			HTML tooltip container goes below.
			It is added at the very bottom of the page to avoid Z-index issues.
		-->
		<div id="tooltip"></div>
	</body>
</html>

Sample Description

How to use this sample?

Move the mouse over any of the event markers to see events they fire, all information that can be obtained from the event is displayed in Event Log table on the right.

to top

How it works

This samples handles all events that can be handled for non-merged event markers (listed below) and gets information from eventMarker object that can be obtained in the event handler.

You can read more about event markers in Event Markers section and find full list of available events and handling guide in Events Handling article.

to top

AnyChartStock JavaScript API

This sample uses the following methods, properties and events from AnyChartStock JavaScript API:

Item Type Description
bgColor Property (HEX Color String ) Flash movie background color.
target Property (DOM Object) Link to a chart container DOM object.
wMode Property (String) Sets the Window Mode property of the Flash movie for transparency, layering, and positioning in the browser.
setXMLFile Method Sets chart XML configuration file path.
write Method Adds the chart to HTML DOM as a child of the specified container.
onEventMarkerClick Event This event is dispatched when the user clicks an event marker.
onEventMarkerDeselect Event This event is dispatched when an event marker is deselected.
onEventMarkerDoubleClick Event This event is dispatched when the user double clicks an event marker.
onEventMarkerMouseOut Event This event is dispatched when the mouse leaves an event marker.
onEventMarkerMouseOver Event This event is dispatched when an event marker is hovered by the mouse.
onEventMarkerSelect Event This event is dispatched when an event marker is selected.

to top

Prerequisites

This section lists all configuration, data and auxiliary files required for this sample.

Configuration file

CSV files

SWF files

  • AnyChartStock.swf - AnyChart Stock component.
  • Preloader.swf - AnyChart Stock helper component that loads the main component (AnyChartStock.swf) and displays loading progress.

JavaScript Libraries

  • jquery.min.js - A JavaScript jQuery library. Learn more at jQuery official site.
  • AnyChartStock.js - A JavaScript library that is shipped with AnyChart Stock component. It is used to embed the component into HTML DOM and to comunicate with the Flash part.

Additional Files

to top

The information contained in this website is for general information purposes only. All sample data provided on this site is for demonstration purposes only.

The logos and names of other companies and products mentioned on this site are copyright and/or trademarks of their respective owners.

The content on this site, including news, quotes, data and other information, is provided for your personal information only, and is intended for demonstration purposes only. Content on this site is not appropriate for the purposes of making a decision to carry out a transaction or trade. Nor does it provide any form of advice (investment, tax, legal) amounting to investment advice, or make any recommendations regarding particular financial instruments, investments or products.

In no event AnyChart will be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website.

This site may point to other Internet sites that may be of interest to you, however AnyChart does not endorse or take responsibility for the content on such other sites

Market data and News provided by and copyright RediNews, Incorporated.