c3-bar-pie.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //[c3 charts Javascript]
  2. //Project: Riday Admin - Responsive Admin Template
  3. //Primary use: Used only for the morris charts
  4. $(function () {
  5. "use strict";
  6. var t = c3.generate({
  7. bindto: "#bar-chart",
  8. size: { height: 350 },
  9. color: { pattern: ["#689f38"] },
  10. data: {
  11. columns: [
  12. ["option1", 30, 200, 100, 400, 150, 250]
  13. ],
  14. type: "bar"
  15. },
  16. axis: { rotated: !0 },
  17. grid: { y: { show: !0 } }
  18. });
  19. // Callback that creates and populates a data table, instantiates the column chart, passes in the data and draws it.
  20. var columnChart = c3.generate({
  21. bindto: '#column-chart',
  22. size: { height: 350 },
  23. color: {
  24. pattern: ['#38649f', '#389f99', '#ee1044']
  25. },
  26. // Create the data table.
  27. data: {
  28. columns: [
  29. ['data1', 30, 200, 100, 400, 150, 250],
  30. ['data2', 130, 100, 140, 200, 150, 50]
  31. ],
  32. type: 'bar'
  33. },
  34. bar: {
  35. width: {
  36. ratio: 0.9 // this makes bar width 50% of length between ticks
  37. }
  38. // or
  39. //width: 100 // this makes bar width 100px
  40. },
  41. grid: {
  42. y: {
  43. show: true
  44. }
  45. }
  46. });
  47. // Instantiate and draw our chart, passing in some options.
  48. setTimeout(function() {
  49. columnChart.load({
  50. columns: [
  51. ['data3', 130, -150, 200, 300, -200, 100]
  52. ]
  53. });
  54. }, 1000);
  55. var o = c3.generate({
  56. bindto: "#donut-chart",
  57. color: { pattern: ["#673ab7", "#4974e0", "#3db76b"] },
  58. data: {
  59. columns: [
  60. ['data1', 200],
  61. ['data2', 100],
  62. ['data3', 50]
  63. ],
  64. type: "donut",
  65. onclick: function(o, n) { console.log("onclick", o, n) },
  66. onmouseover: function(o, n) { console.log("onmouseover", o, n) },
  67. onmouseout: function(o, n) { console.log("onmouseout", o, n) }
  68. },
  69. donut: { title: "Total Data" }
  70. });
  71. setTimeout(function() {
  72. o.load({
  73. columns: [
  74. ["setosa_x", 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3.0, 3.0, 4.0, 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3.0, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3.0, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3.0, 3.8, 3.2, 3.7, 3.3],
  75. ["versicolor_x", 3.2, 3.2, 3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2.0, 3.0, 2.2, 2.9, 2.9, 3.1, 3.0, 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3.0, 2.8, 3.0, 2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3.0, 3.4, 3.1, 2.3, 3.0, 2.5, 2.6, 3.0, 2.6, 2.3, 2.7, 3.0, 2.9, 2.9, 2.5, 2.8],
  76. ["setosa", 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2]
  77. ]
  78. })
  79. }, 1500),
  80. setTimeout(function() { o.unload({ ids: "data1" }), o.unload({ ids: "data2" }), o.unload({ ids: "data3" })}, 2500)
  81. var o = c3.generate({
  82. bindto: "#pie-chart",
  83. color: { pattern: ['#38649f', '#389f99', '#ee1044'] },
  84. data: {
  85. columns: [
  86. ['data1', 30],
  87. ['data2', 130],
  88. ['data3', 10]
  89. ],
  90. type: "pie",
  91. onclick: function(o, n) { console.log("onclick", o, n) },
  92. onmouseover: function(o, n) { console.log("onmouseover", o, n) },
  93. onmouseout: function(o, n) { console.log("onmouseout", o, n) }
  94. }
  95. });
  96. setTimeout(function() {
  97. o.load({
  98. columns: [
  99. ["setosa_x", 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3.0, 3.0, 4.0, 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3.0, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3.0, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3.0, 3.8, 3.2, 3.7, 3.3],
  100. ["versicolor_x", 3.2, 3.2, 3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2.0, 3.0, 2.2, 2.9, 2.9, 3.1, 3.0, 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3.0, 2.8, 3.0, 2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3.0, 3.4, 3.1, 2.3, 3.0, 2.5, 2.6, 3.0, 2.6, 2.3, 2.7, 3.0, 2.9, 2.9, 2.5, 2.8],
  101. ["setosa", 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2]
  102. ]
  103. })
  104. }, 1500), setTimeout(function() { o.unload({ ids: "data1" }), o.unload({ ids: "data2" }), o.unload({ ids: "data3" }) }, 2500)
  105. var a = c3.generate({
  106. bindto: "#stacked-bar",
  107. size: { height: 400 },
  108. color: { pattern: ["#689f38", "#38649f", "#389f99", "#ee1044"] },
  109. data: {
  110. columns: [
  111. ['data1', -30, 200, 200, 400, -150, 250],
  112. ['data2', 130, 100, -100, 200, -150, 50],
  113. ['data3', -230, 200, 200, -300, 250, 250]
  114. ],
  115. type: "bar",
  116. groups: [
  117. ["data1", "data2"]
  118. ]
  119. },
  120. grid: { y: { show: !0 } },
  121. axis: { rotated: !0 }
  122. });
  123. setTimeout(function() {
  124. a.groups([
  125. ["data1", "data2", "data3"]
  126. ])
  127. }, 1e3), setTimeout(function() {
  128. a.load({
  129. columns: [
  130. ['data4', 100, -50, 150, 200, -300, -100]
  131. ]
  132. })
  133. }, 1500), setTimeout(function() {
  134. a.groups([
  135. ["data1", "data2", "data3", "data4"]
  136. ])
  137. }, 2e3)
  138. // Callback that creates and populates a data table, instantiates the stacked column chart, passes in the data and draws it.
  139. var stackedColumnChart = c3.generate({
  140. bindto: '#stacked-column',
  141. size: { height: 400 },
  142. color: {
  143. pattern: ['#673ab7', '#4974e0', '#3db76b', '#ec407a']
  144. },
  145. // Create the data table.
  146. data: {
  147. columns: [
  148. ['data1', -30, 200, 200, 400, -150, 250],
  149. ['data2', 130, 100, -100, 200, -150, 50],
  150. ['data3', -230, 200, 200, -300, 250, 250]
  151. ],
  152. type: 'bar',
  153. groups: [
  154. ["data1", "data2"]
  155. ]
  156. },
  157. grid: {
  158. y: {
  159. show: true
  160. }
  161. },
  162. });
  163. // Instantiate and draw our chart, passing in some options.
  164. setTimeout(function() {
  165. stackedColumnChart.groups([
  166. ["data1", "data2", "data3"]
  167. ]);
  168. }, 1000);
  169. setTimeout(function() {
  170. stackedColumnChart.load({
  171. columns: [
  172. ['data4', 100, -50, 150, 200, -300, -100]
  173. ]
  174. });
  175. }, 1500);
  176. setTimeout(function() {
  177. stackedColumnChart.groups([
  178. ["data1", "data2", "data3", "data4"]
  179. ]);
  180. }, 2000);
  181. });