<html> <head> <title>Get Annotation List as JSON or XML</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"> // 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"); // Writing the flash object into the page DOM. chart.write("chartContainer"); // Enabling disabled buttons when chart has rendered chart.onChartDraw = function () { document.getElementById("btnGetListAsJSON").removeAttribute("disabled"); document.getElementById("btnGetListAsXML").removeAttribute("disabled"); document.getElementById("btnOnePointAnnotStart").removeAttribute("disabled"); document.getElementById("btnTwoPointsAnnotStart").removeAttribute("disabled"); document.getElementById("btnThreePointsAnnotStart").removeAttribute("disabled"); document.getElementById("btnRemoveAll").removeAttribute("disabled"); } // Enable StopDrawingAnnotation button when any annotation drawing has started chart.onAnnotationDrawingStart = function (id) { document.getElementById("btnStopDrawing").removeAttribute("disabled"); } // Disable StopDrawingAnnotation button when annotation drawing successfully finished chart.onAnnotationDrawingFinish = function (id) { document.getElementById("btnStopDrawing").setAttribute("disabled", "disabled"); } // Enable btnRemoveSelectedAnnotation button when any annotation has been selected chart.onAnnotationSelect = function (id) { document.getElementById("btnRemoveSelected").removeAttribute("disabled"); } // Disable btnRemoveSelectedAnnotation button when no annotation is selected. // This event also fires when the selected annotation has been removed, so we don't // need to duplicate this disabling code to the removeSelectedAnnotation() function. chart.onAnnotationDeselect = function (id) { document.getElementById("btnRemoveSelected").setAttribute("disabled", "disabled"); } // All available one-anchor-point annotations var onePointAnnotations = [ "VerticalLine", "HorizontalLine", "Arrow", "Label" ]; // All available two-anchor-points annotations var twoPointAnnotations = [ "Line", "FibonacciFan", "FibonacciArc", "FibonacciRetracement", "FibonacciTimezones", "InfiniteLine", "Ray", "Rectangle", "Ellipse" ]; // All available three-anchor-points annotations var threePointAnnotations = [ "Triangle", "TrendChannel", "AndrewsPitchfork" ]; // Start drawing random one-anchor-point annotation function startOnePointAnnotation() { chart.startDrawingAnnotation(onePointAnnotations[Math.floor(Math.random() * onePointAnnotations.length)]); } // Start drawing random two-anchor-points annotation function startTwoPointsAnnotation() { chart.startDrawingAnnotation(twoPointAnnotations[Math.floor(Math.random() * twoPointAnnotations.length)]); } // Start drawing random three-anchor-points annotation function startThreePointsAnnotation() { chart.startDrawingAnnotation(threePointAnnotations[Math.floor(Math.random() * threePointAnnotations.length)]); } // Stop drawing annotation function stopDrawing() { chart.stopDrawingAnnotation(); document.getElementById("btnStopDrawing").setAttribute("disabled", "disabled"); } // Removes selected annotation function removeSelected() { var id = chart.getSelectedAnnotationId() chart.removeAnnotation(id); } // Removes all annotations from the chart function removeAll() { chart.removeAllAnnotations(); } // Gets annotation list as JSON function getListAsJSON() { document.getElementById("log").value = traceObject(chart.getAnnotationListAsJSON()); } // Gets annotation list as XML function getListAsXML() { document.getElementById("log").value = chart.getAnnotationListAsXML(); } // Auxiliary function that turns object into json string function traceObject(obj) { return chart.flashObject.traceObject(obj); } </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-bottom:2px; padding-top:2px; padding-left:10px; padding-right:10px; text-align:left; } table.settings tr td input { width: 100%; } #chartContainer { width: 700px; height: 300px; } #log { width: 700px; height: 300; background-color: #FEFEFE; border-width: 1px; border-color: #C9C6C2; border-style: solid; } </style> </head> <body> <table> <tr><td> <table class="settings"> <tr><th>Chart:</th></tr> <tr><td id="chartContainer"><!-- Chart Container --></td></tr> <tr><th>Object Model:</th></tr> <tr><td><textarea id="log" spellcheck="false"></textarea></td></tr> </table> </td> <td valign="top"> <table> <tr><td> <table class="settings"> <tr> <th>Available Action</th> </tr> <tr> <td><input id="btnOnePointAnnotStart" type="button" value="Add one-anchor-point annotation" onclick="startOnePointAnnotation();" disabled="disabled" autocomplete="off"/></td> </tr> <tr> <td><input id="btnTwoPointsAnnotStart" type="button" value="Add two-anchor-points annotation" onclick="startTwoPointsAnnotation();" disabled="disabled" autocomplete="off"/></td> </tr> <tr> <td><input id="btnThreePointsAnnotStart" type="button" value="Add three-anchor-points annotation" onclick="startThreePointsAnnotation();" disabled="disabled" autocomplete="off"/></td> </tr> <tr> <td><input id="btnStopDrawing" type="button" value="Stop drawing annotations" onclick="stopDrawing();" disabled="disabled" autocomplete="off"/></td> </tr> <tr> <td><input id="btnRemoveSelected" type="button" value="Remove selected annotation" onclick="removeSelected();" disabled="disabled" autocomplete="off"/></td> </tr> <tr> <td><input id="btnRemoveAll" type="button" value="Remove all annotations" onclick="removeAll();" disabled="disabled" autocomplete="off"/></td> </tr> </table> </td></tr><tr><td> <table class="settings"> <tr> <th colspan="2">Action</th> </tr> <tr> <td><input id="btnGetListAsJSON" type="button" value="Get annotations as JSON" onclick="getListAsJSON();" disabled="disabled" autocomplete="off"/></td> <td><input id="btnGetListAsXML" type="button" value="Get annotations as XML" onclick="getListAsXML();" disabled="disabled" autocomplete="off"/></td> </tr> </table> </td></tr> </table> </td></tr> </table> </body> </html>
Sample Description
How to use this sample?
Sample shows how to get all annotations using getAnnotationListAsJSON() or getAnnotationListAsXML() methods.
Click "Add one-anchor-point annotation", "Add two-anchor-points annotation" or "Add three-anchor-points annotation" to draw a random annotation. To abort drawing click "Stop drawing annotations". Remove one or all using "Remove selected annotation" and "Remove all annotations" buttons.
To get settings of all annotations in the chart in JSON format, click "Get annotations in JSON", to get them in XML click"Get annotations as XML".
How it works
When you press "Add one-anchor-point annotation", "Add two-anchor-points annotation" or "Add three-anchor-points annotation", startDrawingAnnotaiton() starts the drawing mode. removeAnnotation() and removeAllAnnotation() remove annotations upon removal buttons click, stopDrawingAnnotation() method aborts drawing.
To get a list of all annotations in a chart you should use getAnnotationListAsJSON() or getAnnotationListAsXML() method, which return lists in JSON or XML format. You can use this data to store annotation drawn or analyse them. Learn more about annotations in Working with annotations article.
AnyChartStock JavaScript API
This sample uses the following methods, properties and events from AnyChartStock JavaScript API:
Item | Type | Description |
---|---|---|
flashObject | Property (DOM Object) | Link to a created Flash DOM object, that is used to show charts. |
getAnnotationListAsJSON | Method | Returns an array with objects of annotation type, which contains all annotations in all charts. |
getAnnotationListAsXML | Method | Returns an XML string with all annotations. XML of annotations is formatted as <annotation_list> node. |
getSelectedAnnotationId | Method | Returns id of the selected annotation. |
removeAllAnnotations | Method | Removes all annotations from all charts. |
removeAnnotation | Method | Removes an annotation from the chart. |
setXMLFile | Method | Sets chart XML configuration file path. |
startDrawingAnnotation | Method | Starts drawing annotation of a given type. |
stopDrawingAnnotation | Method | Ends drawing mode started by startDrawingAnnotation() method. |
write | Method | Adds the chart to HTML DOM as a child of the specified container. |
onAnnotationDeselect | Event | This event is dispatched when an annotation looses focus. |
onAnnotationDrawingFinish | Event | This event is dispatched when an annotation drawing initiated by startDrawingAnnotation() finishes. |
onAnnotationDrawingStart | Event | This event is dispatched when startDrawingAnnotation() methods is used and drawing has successfully started. |
onAnnotationSelect | Event | This event is dispatched when an annotation is selected. |
onChartDraw | Event | This event is dispatched when the AnyChart Stock is drawn. |
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
- 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.
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.