<html>
	<head>
		<title>Changing Series Properties Dynamically</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>
		<script type="text/javascript" language="javascript" src="./js/jquery.min.js"></script>
		
		<!-- chart size settings -->
		<style type="text/css">
			#chartContainer {
				width: 700px;
				height: 520px;
				float: left;
			}
		</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");
			// 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");
						
			function onSeriesTypeChange() {
				// Change the type of the series in the object model.
				chart.getSeriesById("idMainChart", "idSeriesA").type = $("#seriesType").val();
				// Apply changes.
				chart.applySettingsChanges();
			}

			function onSeriesColorChange() {
				// Change the color of the series.
				chart.getSeriesById("idMainChart", "idSeriesA").color = $("#seriesColor").val();
				// Apply changes.
				chart.applySettingsChanges();
			}

			function onSeriesNameChange() {
				// Change the name of the series.
				chart.getSeriesById("idMainChart", "idSeriesA").name = $("#seriesName").val();
				// Apply changes.
				chart.applySettingsChanges();
			}
			
			//---------------------------------------------------------------------------------------------------
			//		html events binding
			//---------------------------------------------------------------------------------------------------
			
			$(function() {
				$("#seriesType").change(onSeriesTypeChange);
				$("#seriesColor").change(onSeriesColorChange);
				$("#seriesName").change(onSeriesNameChange);
			});
			
			//---------------------------------------------------------------------------------------------------
			//		Enable html controls
			//---------------------------------------------------------------------------------------------------
			
			chart.onChartDraw = function() {
				$("#seriesType").removeAttr("disabled");
				$("#seriesColor").removeAttr("disabled");
				$("#seriesName").removeAttr("disabled");
				chart.onChartDraw = null;
			}
		</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;
				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 with series settings -->
		<table class="settings">
			<tr>
				<th colspan="2">Series Settings:</th>
			</tr>
			<tr>
				<td>Series Type:</td>
				<td><select id="seriesType" disabled="disabled" autocomplete="off">
					<option value="Candlestick">Candlestick</option>
					<option value="OHLC">OHLC</option>
					<option value="Line" selected="true">Line</option>
					<option value="Area">Area</option>
					<option value="Bar">Bar</option>
					<option value="StepLine">StepLine</option>
					<option value="Stick">Stick</option>
					<option value="Marker">Marker</option>
					<option value="Spline">Spline</option>
					<option value="SplineArea">SplineArea</option>
					<option value="StepLineArea">StepLineArea</option>
					<option value="RangeBar">RangeBar</option>
					<option value="RangeArea">RangeArea</option>
					<option value="RangeSplineArea">RangeSplineArea</option>
				</select></td>
			</tr>
			<tr>
				<td>Series Color:</td>
				<td><input type="text" id="seriesColor" disabled="disabled" value="#DC3912" autocomplete="off"></td>
			</tr>
			<tr>
				<td>Series Name:</td>
				<td><input type="text" id="seriesName" disabled="disabled" value="Series A" autocomplete="off"></td>
			</tr>
		</table>
	</body>
</html>

Sample Description

How to use this sample?

In this sample you can change Series Type, Color and Name on-the-fly using controls to the right of the chart.

to top

How it works

All the changes in charts can be made using object model as described in Updating Chart using Object Model.

This sample uses auxiliary getSeriesById function to obtain a link to series object and applySettingsChanges method to commit the changes made.

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.
applySettingsChanges Method Commits changes made to settings element of 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.
onChartDraw Event This event is dispatched when the AnyChart Stock is drawn.

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.

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.