api_flow.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="/css/c3.css">
  4. <style>
  5. .c3-region-1 {
  6. fill: #dd3333;
  7. fill-opacity: 0.8
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <div id="chart"></div>
  13. <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
  14. <script src="/js/c3.js"></script>
  15. <script>
  16. var padding = {}, types = {}, chart, generate = function () { return c3.generate({
  17. data: {
  18. columns: [
  19. ['data1'],
  20. ['data2'],
  21. ],
  22. types: types,
  23. labels: true
  24. },
  25. bar: {
  26. width: 10
  27. },
  28. axis: {
  29. x: {
  30. padding: padding
  31. },
  32. y: {
  33. /*
  34. min: -100,
  35. max: 1000
  36. */
  37. }
  38. },
  39. grid: {
  40. x: {
  41. show: true,
  42. lines: [{value: 3, text:'Label 3'}, {value: 4.5, text: 'Label 4.5'}]
  43. },
  44. y: {
  45. show: true
  46. }
  47. },
  48. regions: [
  49. {start:2, end:4, class:'region1'},
  50. {start:100, end:200, axis:'y'},
  51. ],
  52. });
  53. };
  54. function run() {
  55. chart = generate();
  56. setTimeout(function () {
  57. // Load only one data
  58. chart.flow({
  59. rows: [
  60. ['data1', 'data2', 'data3'],
  61. [500, 100, 200],
  62. [200, null, null],
  63. [100, 50, null]
  64. ],
  65. duration: 1500,
  66. done: function () {
  67. // Load 2 data without data2 and remove 1 data
  68. chart.flow({
  69. columns: [
  70. ['data1', 200, 300],
  71. ['data3', 100, 100]
  72. ],
  73. length: 0,
  74. duration: 1500,
  75. done: function () {
  76. chart.flow({
  77. columns: [
  78. ['data1', 200, 300],
  79. ['data2', 200, 300],
  80. ['data3', 100, 100]
  81. ],
  82. length: 2,
  83. duration: 1500,
  84. done: function () {
  85. chart.flow({
  86. columns: [
  87. ['data1', 500],
  88. ['data2', 100],
  89. ['data3', 200]
  90. ],
  91. length: 1,
  92. duration: 1500,
  93. });
  94. }
  95. });
  96. }// done
  97. });
  98. },
  99. });
  100. }, 1000);
  101. setTimeout(function () {
  102. chart.flow({
  103. columns: [
  104. ['data1', 250],
  105. ['data2', 350],
  106. ['data3', 150]
  107. ],
  108. length: 0
  109. });
  110. }, 9000);
  111. setTimeout(function () {
  112. chart.flow({
  113. columns: [
  114. ['data1', 100],
  115. ['data2', 50],
  116. ['data3', 300]
  117. ],
  118. length: 2
  119. });
  120. }, 10000);
  121. setTimeout(function () {
  122. chart.flow({
  123. columns: [
  124. ['data1', 600],
  125. ['data2', 400],
  126. ['data3', 500]
  127. ],
  128. to: 2,
  129. });
  130. }, 11000);
  131. setTimeout(function () {
  132. chart.flow({
  133. columns: [
  134. ['data1', 100],
  135. ['data2', 200],
  136. ['data3', 300]
  137. ]
  138. });
  139. }, 12000);
  140. setTimeout(function () {
  141. chart = generate();
  142. }, 13000);
  143. setTimeout(function () {
  144. chart.flow({
  145. columns: [
  146. ['data1', 500, 100],
  147. ['data2', 100, 200],
  148. ['data3', 200, 300],
  149. ],
  150. duration: 1500,
  151. done: function () {
  152. chart.flow({
  153. columns: [
  154. ['data1', 200],
  155. ['data3', 100]
  156. ],
  157. // duration: 1000,
  158. length: 1
  159. });
  160. },
  161. });
  162. }, 14000);
  163. setTimeout(function () {
  164. chart.flow({
  165. columns: [
  166. ['data1', 200],
  167. ['data2', 300],
  168. ['data3', 100]
  169. ],
  170. to: 1,
  171. });
  172. }, 18000);
  173. setTimeout(function () {
  174. chart.flow({
  175. columns: [
  176. ['data1', 200],
  177. ['data2', 300],
  178. ['data3', 400]
  179. ]
  180. });
  181. }, 19000);
  182. }
  183. run();
  184. // Test for no padding
  185. setTimeout(function () {
  186. padding = {left: 0, right: 0};
  187. run();
  188. }, 22000);
  189. // Test for other chart types
  190. setTimeout(function () {
  191. types = {
  192. data2: 'area',
  193. data3: 'bar',
  194. };
  195. run();
  196. }, 45000);
  197. </script>
  198. </body>
  199. </html>