api_flow_timeseries.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="../css/c3.css">
  4. </head>
  5. <body>
  6. <div id="chart"></div>
  7. <script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
  8. <script src="../js/c3.js"></script>
  9. <script>
  10. var padding = {}, types = {};
  11. var generate = function () { return c3.generate({
  12. data: {
  13. x: 'x',
  14. columns: [
  15. ['x', ],
  16. ['data1', ],
  17. ['data2', ],
  18. // ['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-10', '2013-01-11', '2013-01-12'],
  19. // ['data1', 30, 200, 100, 400, 150, 250],
  20. // ['data2', 310, 400, 200, 100, 450, 150],
  21. // ['data3', 310, 400, 200, 100, null, 150],
  22. ],
  23. types: types,
  24. // labels: true
  25. },
  26. bar: {
  27. width: 10
  28. },
  29. axis: {
  30. x: {
  31. type: 'timeseries',
  32. tick: {
  33. format: '%m/%d',
  34. },
  35. padding: padding
  36. },
  37. y: {
  38. /*
  39. min: -100,
  40. max: 1000
  41. */
  42. }
  43. },
  44. /* not supported yet
  45. grid: {
  46. x: {
  47. show: true
  48. },
  49. y: {
  50. show: true
  51. }
  52. }
  53. */
  54. }); }, chart;
  55. function run() {
  56. chart = generate();
  57. setTimeout(function () {
  58. chart.flow({
  59. columns: [
  60. ['x', '2013-01-21'],
  61. ['data1', 500],
  62. ['data3', 200],
  63. ],
  64. duration: 1500
  65. });
  66. }, 1000);
  67. setTimeout(function () {
  68. chart.flow({
  69. columns: [
  70. ['x', '2013-02-01', '2013-02-08', '2013-02-15'],
  71. ['data1', 200, 400, 300],
  72. ['data2', 100, 300, 200],
  73. ['data3', 100, 200, 50]
  74. ],
  75. length: 1,
  76. duration: 1500
  77. });
  78. }, 4000);
  79. setTimeout(function () {
  80. chart.flow({
  81. columns: [
  82. ['x', '2013-03-01', '2013-03-08'],
  83. ['data1', 200, 500],
  84. ['data2', 300, 400],
  85. ['data3', 400, 200]
  86. ],
  87. to: '2013-02-08',
  88. duration: 1500
  89. });
  90. }, 7000);
  91. setTimeout(function () {
  92. chart.flow({
  93. columns: [
  94. ['x', '2013-03-15', '2013-05-01'],
  95. ['data1', 200, 500],
  96. ['data2', 300, 400],
  97. ['data3', 400, 200]
  98. ],
  99. length: 0,
  100. duration: 1500
  101. });
  102. }, 10000);
  103. setTimeout(function () {
  104. chart = generate();
  105. }, 14000);
  106. setTimeout(function () {
  107. chart.flow({
  108. columns: [
  109. ['x', '2013-01-21', '2013-01-25', '2013-01-26'],
  110. ['data1', 500, 300, 100],
  111. ['data3', 200, 150, null],
  112. ],
  113. duration: 1500
  114. });
  115. }, 15000);
  116. setTimeout(function () {
  117. chart.flow({
  118. columns: [
  119. ['x', '2013-02-01'],
  120. ['data1', 200],
  121. ['data2', 100],
  122. ['data3', 100]
  123. ],
  124. length: 0,
  125. duration: 1500
  126. });
  127. }, 18000);
  128. setTimeout(function () {
  129. chart.flow({
  130. columns: [
  131. ['x', '2013-03-01'],
  132. ['data1', 200],
  133. ['data2', 300],
  134. ['data3', 400]
  135. ],
  136. to: '2013-02-01',
  137. duration: 1500
  138. });
  139. }, 21000);
  140. };
  141. run();
  142. setTimeout(function () {
  143. padding = {left: 0, right: 0};
  144. run();
  145. }, 25000);
  146. setTimeout(function () {
  147. types = {
  148. data2: 'area',
  149. data3: 'bar',
  150. }
  151. run();
  152. }, 50000);
  153. </script>
  154. </body>
  155. </html>