chart_bar_stacked_normalized.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
  8. <script src="../js/c3.js"></script>
  9. <script>
  10. var axis_x_type = 'category',
  11. axis_rotated = false;
  12. var generate = function () { return c3.generate({
  13. data: {
  14. columns: [
  15. ['data1', 30, 200, 200, 400, 150, 250],
  16. ['data2', 130, 100, 100, 200, 150, 50],
  17. ['data3', 230, 200, 200, 0, 250, 250]
  18. ],
  19. type: 'bar',
  20. groups: [
  21. ['data1', 'data2', 'data3']
  22. ],
  23. stack: {
  24. normalize: false
  25. }
  26. },
  27. axis: {
  28. x: {
  29. type: axis_x_type
  30. },
  31. rotated: axis_rotated
  32. },
  33. grid: {
  34. y: {
  35. lines: [{value:0}]
  36. }
  37. },
  38. }); }, chart = generate();
  39. function update1() {
  40. chart.data.stackNormalized(true);
  41. }
  42. function update2() {
  43. chart.load({
  44. columns: [['data4', 100, 50, 150, 200, 300, 100]]
  45. });
  46. }
  47. function update3() {
  48. chart.groups([['data1', 'data2', 'data3', 'data4']])
  49. }
  50. function update4() {
  51. chart.hide(['data2', 'data3'])
  52. }
  53. let delay = 1000;
  54. function enqueue(fct) {
  55. setTimeout(fct, delay);
  56. delay += 1000;
  57. }
  58. enqueue(update1);
  59. enqueue(update2);
  60. enqueue(update3);
  61. enqueue(update4);
  62. enqueue(function () {
  63. axis_rotated = true;
  64. chart = generate();
  65. });
  66. enqueue(update1);
  67. enqueue(update2);
  68. enqueue(update3);
  69. enqueue(update4);
  70. </script>
  71. </body>
  72. </html>