data_load.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <html>
  2. <head>
  3. <link href="/css/c3.css" rel="stylesheet" type="text/css">
  4. </head>
  5. <body>
  6. <div id="chart"></div>
  7. <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
  8. <script src="/js/c3.js"></script>
  9. <script>
  10. var chart = c3.generate({
  11. data: {
  12. url: '/data/c3_test.csv',
  13. labels: true,
  14. filter: function (t) {
  15. return t.id !== 'data1';
  16. }
  17. },
  18. subchart: {
  19. show: true
  20. },
  21. zoom: {
  22. enabled: true
  23. },
  24. transition: {
  25. duration: 500
  26. }
  27. });
  28. var queue = [
  29. function () {
  30. chart.load({
  31. url: '/data/c3_test2.csv',
  32. filter: function (t) {
  33. return t.id !== 'data1';
  34. }
  35. });
  36. },
  37. function () {
  38. chart.load({
  39. rows: [
  40. ['data4', 'data5', 'data6'],
  41. [90, 120, 300],
  42. [40, 160, 240],
  43. [50, 200, 290],
  44. [120, 160, 230],
  45. [80, 130, 300],
  46. [90, 220, 320],
  47. [1090, 1220, 1320],
  48. ]
  49. });
  50. },
  51. function () {
  52. chart.unload({
  53. ids: ['data4', 'data5']
  54. });
  55. },
  56. function () {
  57. chart.unload({
  58. ids: 'data6'
  59. });
  60. },
  61. function () {
  62. chart.load({
  63. columns:[
  64. ['data1', 30, 20, 50, 40, 60, 50, 100, 200],
  65. ['data7', 230, 220, 250, 240, 260, 250, 300, 400]
  66. ]
  67. });
  68. },
  69. function () {
  70. chart.load({
  71. json: {
  72. data1: [1030, 1020, 1050, 1040, 1060, 1050, 1100, 1200],
  73. data7: [430, 420, 450, 440, 460, 550, 400, 200]
  74. }
  75. });
  76. },
  77. function () {
  78. chart.load({
  79. columns: [
  80. ['data8', 30, 20, 50, 40, 60, 50],
  81. ],
  82. unload: true,
  83. });
  84. },
  85. function () {
  86. chart.load({
  87. columns: [
  88. ['data9', 130, 120, 150, 140, 160, 150],
  89. ],
  90. unload: ['data7', 'data8'],
  91. });
  92. },
  93. function () {
  94. chart.load({
  95. unload: ['data1', 'data2'],
  96. });
  97. },
  98. function () {
  99. chart.unload();
  100. },
  101. function () {
  102. chart.load({
  103. rows: [
  104. ['data1', 'data2', 'data3'],
  105. [90, 120, 300],
  106. [40, 160, 240],
  107. [50, 200, 290],
  108. [120, 160, 230],
  109. [80, 130, 300],
  110. [90, 220, 320],
  111. ]
  112. });
  113. },
  114. function () {
  115. chart.unload({
  116. ids: ['data2', 'data3']
  117. });
  118. },
  119. ];
  120. var i = 0;
  121. queue.forEach(function (f) {
  122. setTimeout(f, 1500 * i++);
  123. });
  124. </script>
  125. </body>
  126. </html>