<html>
	<head>
		<title>Synchronizing two different charts navigation</title>
		<meta http-equiv="content-type" content="text/html;charset=utf-8"/>	
		<script type="text/javascript" language="javascript" src="./../js/AnyChartStock.js?v=1.9.0r9317"></script>
		
		<!-- chart size settings -->
		<style type="text/css">
			div.chartContainer {
				width: 700px;
				height: 300px;
			}
		</style>
		
		<script type="text/javascript" language="javascript">

			// Creating the first chart object.
		    var chartMSFT = new AnyChartStock("./../swf/AnyChartStock.swf?v=1.9.0r9317", "./../swf/Preloader.swf?v=1.9.0r9317");
		    // Creating the second chart object. 
		    var chartORCL = new AnyChartStock("./../swf/AnyChartStock.swf?v=1.9.0r9317", "./../swf/Preloader.swf?v=1.9.0r9317");

		    // Set onSelectedRangeChange callback that handles all selected range changes for the first chart
			chartMSFT.onSelectedRangeChange = function (startDate, endDate, phase, sender) {
			    switch (sender) {
			        case "external": 
                        // we ignore all range change events from the external source
			            return;
			        case "rangePresets":
			        case "rangePicker":
			        case "mouseWheel":
			        case "mouseSelect": 
                        // all these sources fire all their phases with the same timestamps, 
                        // so we should react only to the last one
			            if (phase == "finish")
			                chartORCL.zoomTo(startDate, endDate);
			            break;
			        case "scrollbar":
			        case "scroller":
			        case "mouseDrag":
			            // these sources fire all their phases with different timestamps, 
			            // so we should react to all of them to provide expected interactivity
			            chartORCL.zoomTo(startDate, endDate);
			            break;
			    }
			};

			// This callback is almost identical to the previous one, except the zoomTo() method owner.
			chartORCL.onSelectedRangeChange = function (startDate, endDate, phase, sender) {
			    switch (sender) {
			        case "external":
			            return;
			        case "rangePresets":
			        case "rangePicker":
			        case "mouseWheel":
			        case "mouseSelect":
			            if (phase == "finish")
			                chartMSFT.zoomTo(startDate, endDate);
			            break;
			        case "scrollbar":
			        case "scroller":
			        case "mouseDrag":
			            if (phase != "start")
			                chartMSFT.zoomTo(startDate, endDate);
			            break;
			    }
			}

			// Setting XML config file.
			chartMSFT.setXMLFile("configMSFT.xml");
			// Writing the flash object into the page DOM.
			chartMSFT.write("chartMSFT");

			// Setting XML config file.
			chartORCL.setXMLFile("configORCL.xml");
			// Writing the flash object into the page DOM.
			chartORCL.write("chartORCL");

		</script>

        <!-- table settings -->
		<style type="text/css">
			table.settings {
				border-style: solid;
				border-width: 1px;
				border-color: #D0CDC9;
			}

			table.settings tr th {
				font:normal 60% Verdana;
				background-color: #DCD9D5;
				font-weight:bold;
				padding-bottom:5px;
				padding-top:5px;
				padding-left:10px;
				padding-right:10px;
				text-align:left;
			}
			table.settings tr td {
				background-color: #F8F4F0;
				font:normal 70% Verdana;
				padding:10px;
				text-align:left;	
			}
		</style>
	</head>
	<body>
        <table class="settings">
            <tr>
              <th>If you change a selected range of any of these two charts, another chart will reflect the changes: it will be zoomed, scrolled or panned.</th>
            </tr>
            <tr><td><div class="chartContainer" id="chartMSFT"><!-- Chart Container --></div></td></tr>
            <tr><td><div class="chartContainer" id="chartORCL"><!-- Chart Container --></div></td></tr>
        </table>
	</body>
</html>

Sample Description

How to use this sample?

If you change selected range of any of these two charts, another chart will reflect the changes. To change the range you can use different ways like scroller, scroll bar, drag plot and so on.

to top

How it works

This sample shows how to make two different charts change selected ranges simultaneously.

Sample is based on onSelectedRangeChange event that is fired every time a selected range changes. Two handlers parse (one for each chart) events information and update another chart using zoomTo method.

to top

AnyChartStock JavaScript API

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

Item Type Description
setXMLFile Method Sets chart XML configuration file path.
write Method Adds the chart to HTML DOM as a child of the specified container.
zoomTo Method Zooms the chart to a custom range.
onSelectedRangeChange Event This event is dispatched when the selected range of the chart is changed.

to top

Prerequisites

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

Configuration files

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

  • 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.

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.