Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

115 wiersze
4.0 KiB

  1. /**
  2. * jqPlot
  3. * Pure JavaScript plotting plugin using jQuery
  4. *
  5. * Version: 1.0.0b2_r792
  6. *
  7. * Copyright (c) 2009-2011 Chris Leonello
  8. * jqPlot is currently available for use in all personal or commercial projects
  9. * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
  10. * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
  11. * choose the license that best suits your project and use it accordingly.
  12. *
  13. * Although not required, the author would appreciate an email letting him
  14. * know of any substantial use of jqPlot. You can reach the author at:
  15. * chris at jqplot dot com or see http://www.jqplot.com/info.php .
  16. *
  17. * If you are feeling kind and generous, consider supporting the project by
  18. * making a donation at: http://www.jqplot.com/donate.php .
  19. *
  20. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  21. *
  22. * version 2007.04.27
  23. * author Ash Searle
  24. * http://hexmen.com/blog/2007/03/printf-sprintf/
  25. * http://hexmen.com/js/sprintf.js
  26. * The author (Ash Searle) has placed this code in the public domain:
  27. * "This code is unrestricted: you are free to use it however you like."
  28. *
  29. */
  30. (function($) {
  31. /**
  32. * Class: $.jqplot.ciParser
  33. * Data Renderer function which converts a custom JSON data object into jqPlot data format.
  34. * Set this as a callable on the jqplot dataRenderer plot option:
  35. *
  36. * > plot = $.jqplot('mychart', [data], { dataRenderer: $.jqplot.ciParser, ... });
  37. *
  38. * Where data is an object in JSON format or a JSON encoded string conforming to the
  39. * City Index API spec.
  40. *
  41. * Note that calling the renderer function is handled internally by jqPlot. The
  42. * user does not have to call the function. The parameters described below will
  43. * automatically be passed to the ciParser function.
  44. *
  45. * Parameters:
  46. * data - JSON encoded string or object.
  47. * plot - reference to jqPlot Plot object.
  48. *
  49. * Returns:
  50. * data array in jqPlot format.
  51. *
  52. */
  53. $.jqplot.ciParser = function (data, plot) {
  54. var ret = [],
  55. line,
  56. temp,
  57. i, j, k, kk;
  58. if (typeof(data) == "string") {
  59. data = $.jqplot.JSON.parse(data, handleStrings);
  60. }
  61. else if (typeof(data) == "object") {
  62. for (k in data) {
  63. for (i=0; i<data[k].length; i++) {
  64. for (kk in data[k][i]) {
  65. data[k][i][kk] = handleStrings(kk, data[k][i][kk]);
  66. }
  67. }
  68. }
  69. }
  70. else {
  71. return null;
  72. }
  73. // function handleStrings
  74. // Checks any JSON encoded strings to see if they are
  75. // encoded dates. If so, pull out the timestamp.
  76. // Expects dates to be represented by js timestamps.
  77. function handleStrings(key, value) {
  78. var a;
  79. if (value != null) {
  80. if (value.toString().indexOf('Date') >= 0) {
  81. //here we will try to extract the ticks from the Date string in the "value" fields of JSON returned data
  82. a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
  83. if (a) {
  84. return parseInt(a[1], 10);
  85. }
  86. }
  87. return value;
  88. }
  89. }
  90. for (var prop in data) {
  91. line = [];
  92. temp = data[prop];
  93. switch (prop) {
  94. case "PriceTicks":
  95. for (i=0; i<temp.length; i++) {
  96. line.push([temp[i]['TickDate'], temp[i]['Price']]);
  97. }
  98. break;
  99. case "PriceBars":
  100. for (i=0; i<temp.length; i++) {
  101. line.push([temp[i]['BarDate'], temp[i]['Open'], temp[i]['High'], temp[i]['Low'], temp[i]['Close']]);
  102. }
  103. break;
  104. }
  105. ret.push(line);
  106. }
  107. return ret;
  108. };
  109. })(jQuery);