3 * Pure JavaScript plotting plugin using jQuery
8 * Copyright (c) 2009-2012 Chris Leonello
9 * jqPlot is currently available for use in all personal or commercial projects
10 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
11 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
12 * choose the license that best suits your project and use it accordingly.
14 * Although not required, the author would appreciate an email letting him
15 * know of any substantial use of jqPlot. You can reach the author at:
16 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
18 * If you are feeling kind and generous, consider supporting the project by
19 * making a donation at: http://www.jqplot.com/donate.php .
21 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
25 * http://hexmen.com/blog/2007/03/printf-sprintf/
26 * http://hexmen.com/js/sprintf.js
27 * The author (Ash Searle) has placed this code in the public domain:
28 * "This code is unrestricted: you are free to use it however you like."
33 * Class: $.jqplot.ciParser
34 * Data Renderer function which converts a custom JSON data object into jqPlot data format.
35 * Set this as a callable on the jqplot dataRenderer plot option:
37 * > plot = $.jqplot('mychart', [data], { dataRenderer: $.jqplot.ciParser, ... });
39 * Where data is an object in JSON format or a JSON encoded string conforming to the
40 * City Index API spec.
42 * Note that calling the renderer function is handled internally by jqPlot. The
43 * user does not have to call the function. The parameters described below will
44 * automatically be passed to the ciParser function.
47 * data - JSON encoded string or object.
48 * plot - reference to jqPlot Plot object.
51 * data array in jqPlot format.
54 $.jqplot.ciParser = function (data, plot) {
60 if (typeof(data) == "string") {
61 data = $.jqplot.JSON.parse(data, handleStrings);
64 else if (typeof(data) == "object") {
66 for (i=0; i<data[k].length; i++) {
67 for (kk in data[k][i]) {
68 data[k][i][kk] = handleStrings(kk, data[k][i][kk]);
78 // function handleStrings
79 // Checks any JSON encoded strings to see if they are
80 // encoded dates. If so, pull out the timestamp.
81 // Expects dates to be represented by js timestamps.
83 function handleStrings(key, value) {
86 if (value.toString().indexOf('Date') >= 0) {
87 //here we will try to extract the ticks from the Date string in the "value" fields of JSON returned data
88 a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
90 return parseInt(a[1], 10);
97 for (var prop in data) {
102 for (i=0; i<temp.length; i++) {
103 line.push([temp[i]['TickDate'], temp[i]['Price']]);
107 for (i=0; i<temp.length; i++) {
108 line.push([temp[i]['BarDate'], temp[i]['Open'], temp[i]['High'], temp[i]['Low'], temp[i]['Close']]);