<html>
	<head>
		<title></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">
			#chartContainer {
				width: 600px;
				height: 450px;
				float: left;
			}
		</style>
		
		<!-- jQuery is used to work with DOM -->
		<script type="text/javascript" src="js/jquery.min.js"></script>
		
		<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");
			// NOTE: needConfig flag set to true, provides an ability to work with chart objectModel
			chart.needConfig = true;
			// Writing the flash object into the page DOM.
			chart.write("chartContainer");
			
			// Data source updating function
			function updateChart() {
				// Data source address
				// GET-request is formed
			    var url = "http://anychart.com/products/stock/online-demos/html-js-samples-center/dynamic-data-source/proxy.php?s=" + 
                        $("#symbol").val() + "&grouping=" + $("input[@name=interval]:checked").val();
				// Setting new data source address
				chart.objectModel.data.dataSets[0].sourceUrl = url;
				// Changing chart title
				chart.objectModel.settings.labels[0].format = $("#symbol option:selected").text() +": Historical Prices";
				// Changing series title
				chart.getSeriesById("idMainChart","idMainSeries").name = $("#symbol").val();
				// Applying all changes made to the object model
				chart.applyConfigChanges();
			}
			
		</script>
		
		<style type="text/css">
			/* settings table */
			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;
				text-align:left;
			}
			table.settings tr td {
				background-color: #F8F4F0;
				font:normal 70% Verdana;
				padding-bottom:2px;
				padding-top:2px;
				padding-left:10px;
				text-align:left;	
			}
		</style>
	</head>
	<body>
		<div id="chartContainer"><!-- Chart Container --></div>
		<table class="settings">
			<tr>
				<th width="55" colspan="2">Data Source:</th>
			</tr>
			<tr>
				<td>Symbol:</td>
				<td>
				<select id="symbol" autocomplete="off">
					<optgroup label="Major World Indices">
						<option value="^DJI">Dow Jones Industrial Average (DJI: ^DJI)</option>
						<option value="^IXIC">NASDAQ Composite (Nasdaq: ^IXIC)</option>
						<option value="^GSPC">S&amp;P 500 INDEX,RTH (SNP: ^GSPC)</option>
						<option value="^FTSE">FTSE 100 (FTSE: ^FTSE)</option>
						<option value="^GDAXI">DAX (XETRA: ^GDAXI)</option>
						<option value="^FCHI">CAC 40 (Paris: ^FCHI)</option>
						<option value="^N225">NIKKEI 225 (Osaka: ^N225)</option>
						<option value="^HSI">HANG SENG INDEX (HKSE: ^HSI)</option>
					</optgroup>
				
					<optgroup label="Technology">
						<option value="MSFT">Microsoft Corporation (NasdaqGS: MSFT)</option>
						<option value="AAPL">Apple Inc. (NasdaqGS: AAPL)</option>
						<option value="ORCL">Oracle Corporation (NasdaqGS: ORCL)</option>
						<option value="IBM">International Business Machines (NYSE: IBM)</option>
						<option value="SAP">SAP AG ADS (NYSE: SAP)</option>
						<option value="CSCO">Cisco Systems, Inc. (NasdaqGS: CSCO)</option>
						<option value="JNPR">Juniper Networks, Inc. Common S (NYSE: JNPR)</option>
						<option value="RVBD">Riverbed Technology, Inc. (NasdaqGS: RVBD)</option>
						<option value="FNSR">Finisar Corporation (NasdaqGS: FNSR)</option>
						<option value="ALU">Alcatel-Lucent Common Stock (NYSE: ALU)</option>
						<option value="HPQ">Hewlett-Packard Company Common (NYSE: HPQ)</option>
						<option value="DELL">Dell Inc. (NasdaqGS: DELL)</option>
						<option value="PALM">Palm, Inc. (NasdaqGS: PALM)</option>
					</optgroup>

					<optgroup label="Financial">
						<option value="C">Citigroup, Inc. Common Stock (NYSE: C)</option>
						<option value="BAC">Bank of America Corporation Com (NYSE: BAC)</option>
						<option value="HBC">HSBC Holdings, plc. Common Stock (NYSE: HBC)</option>
						<option value="JPM">JP Morgan Chase &amp; Co. Common St (NYSE: JPM)</option>
						<option value="BCS">Barclays PLC Common Stock (NYSE: BCS)</option>
					</optgroup>				
				
					<optgroup label="Auto Manufacturers - Major">
						<option value="TM">Toyota Motor Corporation Common (NYSE: TM)</option>
						<option value="HMC">Honda Motor Company, Ltd. Common (NYSE: HMC)</option>
						<option value="F">Ford Motor Company Common Stock (NYSE: F)</option>
						<option value="SORL">SORL Auto Parts, Inc. (NasdaqGM: SORL)</option>
					</optgroup>
				
					<optgroup label="Major Integrated Oil &amp; Gas">
						<option value="CVX">Chevron Corporation Common Stock (NYSE: CVX)</option>
						<option value="BP">BP p.l.c. Common Stock (NYSE: BP)</option>
						<option value="XOM">Exxon Mobil Corporation Common (NYSE: XOM)</option>
					</optgroup>
				</select>
				</td>
			</tr>
			<tr>
				<td>Interval:</td>
				<td>
					<input type= "radio" checked="true" name="interval" value="d" autocomplete="off"/> Daily
					<br />
					<input type= "radio" name="interval" value="w" autocomplete="off"/> Weekly
					<br />
					<input type= "radio" name="interval" value="m" autocomplete="off"/> Monthly
				</td>
			</tr>
			<tr>
				<td colspan="2"><input type="button" value="Update Chart" onclick="updateChart()"/></td>
			</tr>
		</table>
	</body>
</html>

Sample Description

How to use this sample?

Choose symbol, date range, precision level and press "Update Chart" button - the component will make dynamic GET-requests and loads new data to the chart.

to top

How it works

This example demonstrates how to use dynamic data sources with AnyChart Stock component. Almost in all samples we demonstrate component behavior using static data sets, however, in real world it is important to have an ability to form data sets dynamically.

On of the ways to load new data and settings dynamically in AnyChart Stock is altering all configuration settings of the component (including data sources configuration) using Object model.

The specific feature of this sample is that the data source path is not changed - only GET-parameters of the request are different. The server script determines what data should be given to the component in terms of these parameters. You can see the script source by downloading this sample.

Data source is changed in chart.objectModel.data.dataSets[0].sourceUrl object model property, the url of PHP script is set, with "Symbol" and "Interval" parameters passed to it. Also, some visual settings (chart and series title) are changed using objectModel. After object model editing changes are applied using applyConfigChanges() method.

to top

AnyChartStock JavaScript API

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

Item Type Description
needConfig Property (Boolean) Defines whether the access to full chart configuration object model is required.
objectModel Property (Object) Gets chart configuration as an Object.
applyConfigChanges Method Commits changes made to the objectModel.
getSeriesById Method Gets series object from the object model by its id.
setXMLFile Method Sets chart XML configuration file path.
write Method Adds the chart to HTML DOM as a child of the specified container.

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.