<title>Adding Data into Data Set</title>
		<meta http-equiv="content-type" content="text/html;charset=utf-8"/>	
		<!-- Randomizer script. It is used to make random more smooth. -->
		<script type="text/javascript" language="javascript" src="./js/Randomizer.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: 800px;
				height: 400px;
				float: left;
		<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.
			// Writing the flash object into the page DOM.
			//		Auxiliary Functions
			// Function to format date according to settings defined in data set locale in config.xml
			// Formatting mask: %yyyy-%MM-%dd
			// NOTE: UTC date is used
			function formatDateTime(date) {
				var m = String(date.getUTCMonth()+1);
				if (m.length == 1) m = "0"+m;
				var d = String(date.getUTCDate());
				if (d.length == 1) d = "0"+d;
				var h = String(date.getUTCHours());
				if (h.length == 1) h = "0"+h;
				var min = String(date.getUTCMinutes());
				if (min.length == 1) min = "0"+min;
				return date.getUTCFullYear() + m + d + " "+h+":"+min;
			//		Data insertion
				Function to insert random data
				startDate {Date} start of the range, which data is added to
				endDate {Date} end of the range, which data is added to
				startValue {Number} start value
				endValue {Number} end value
			function insert(startDate, endDate, startValue, endValue) {
				// Create data randomizer. Values go from startValue to endValue. Step: 5
				var randomizer = new Randomizer(startValue, 0,endValue, 5);
				// This variable is used to store CSV row 
				// Date formatting and CSV settings must match those set in config.xml for data set named "dataSet1"
				var newCSVData = "";
				// Date to be incremented 
				var date = new Date(startDate.getTime());

				// while the date hasn't reach the end of the range - keep adding data
				while (date.getTime() < endDate.getTime()) {
					var val = randomizer.next(); // get next random value
					newCSVData += formatDateTime(date)+","+val+"\n"; // add it to CSV string
					date.setUTCHours(date.getUTCHours()+1); // increment date (add 3 hours)
				// add CSV string with data into the data set named "dataSet1"
				chart.appendData("dataSet1", newCSVData);
				// and apply changes
				return chart.commitDataChanges(); 
			//		Data insertion blocks
			// Adding data into the middle of the set
			function insertIntoMiddle() {
				if (insert(new Date(Date.UTC(1971,1,22)),new Date(Date.UTC(1971,2,1)),77,79)) { // if insertion succeeded
					// Disable add button
					document.getElementById("insertMiddle").setAttribute("disabled", "disabled");
			// Adding data in the beginning of the set
			function insertIntoStart() {
				if (insert(new Date(Date.UTC(1971,1,6)),new Date(Date.UTC(1971,1,15)),54,37)) { // if insertion succeeded
					//  Disable add button
					document.getElementById("insertStart").setAttribute("disabled", "disabled");
			// Adding data in the end of the set
			function insertIntoEnd() {
				if (insert(new Date(Date.UTC(1971,2,8)),new Date(Date.UTC(1971,2,17)),85,66)) { // if insertion succeeded
					// Disable add button
					document.getElementById("insertEnd").setAttribute("disabled", "disabled");
			//		Resetting
			// reset function
			function reset() {
				// to reset changes we simply set config file again
				// and put buttons into the initial state
		<!-- 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;
			table.settings tr td {
				background-color: #F8F4F0;
				font:normal 70% Verdana;
			table.settings input {
				width : 220px;
		<div id="chartContainer"><!-- Chart Container --></div>
		<table class="settings">
			<tr><th>Perform operation:</th></tr>
			<tr><td><input id="insertStart" type="button" value="Insert at the beginning of Data-Set" onclick="insertIntoStart()" autocomplete="off"/></td></tr>
			<tr><td><input id="insertMiddle" type="button" value="Insert into middle of Data-Set" onclick="insertIntoMiddle()"  autocomplete="off"/></td></tr>
			<tr><td><input id="insertEnd" type="button" value="Insert at the end of Data-Set" onclick="insertIntoEnd()"  autocomplete="off"/></td></tr>
			<tr><td><input type="button" value="Reset" onclick="reset()" /></td></tr>

Sample Description

How to use this sample?

Use buttons to the right of the chart to insert new data into the chart or "Reset" button to put chart into initial state.

to top

How it works

AnyChart Stock component gives you the ability to add, remove or modify data points in real-time without full chart reloading and redrawing - you can do just what you need in a fast and flexible way.

This sample generates several random data points and inserts them into the data set defined in config.xml using appendData function. Every time new data is inserted commitDataChanges function is called to apply changes.

You can learn everything you need to know about real-time data streaming and update in Real-Time Data Streaming and Data Manipulations article.

to top

AnyChartStock JavaScript API

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

Item Type Description
appendData Method Appends data to the chart.
commitDataChanges Method Commits data appends and data points erasure made by appendData(), removeDataRow() and removeDataRange() method calls.
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


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

  • Randomizer.js - A sample JavaScript library that generates random values.
  • 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.