custom_xs_scale.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 chart = c3.generate({
  11. bindto: '#chart',
  12. data: {
  13. xs : {
  14. 'data1': 'x1',
  15. 'data2': 'x2',
  16. },
  17. columns: [
  18. ['x1', 100, 120, 130, 200, 240, 500],
  19. ['x2', 150, 220, 230, 400, 540, 600, 800],
  20. ['data1', 30, 200, 100, 400, 150, 250],
  21. ['data2', 130, 100, 300, 200, 250, 350, 100],
  22. ],
  23. selection: {
  24. enabled: true
  25. },
  26. onclick: function (d) { console.log("onclick", d); },
  27. onmouseover: function (d) { console.log("onmouseover", d); },
  28. onmouseout: function (d) { console.log("onmouseout", d); }
  29. }
  30. });
  31. setTimeout(function () {
  32. chart.load({
  33. columns: [
  34. ['data1', 100, 210, 150, null, 200, 150],
  35. ['data2', 200, 310, 50, 400, 120, 250, 10],
  36. ]
  37. });
  38. }, 1000);
  39. setTimeout(function () {
  40. chart.load({
  41. columns: [
  42. ['x2', 150, 220, 230, 400, 540, 600, 800],
  43. ['data2', 200, 310, 50, 400, 120, 250, 10],
  44. ['data3', 300, 410, 350, 600, 420, 550, 310],
  45. ],
  46. xs: {
  47. data3: 'x2'
  48. }
  49. });
  50. }, 2000);
  51. setTimeout(function () {
  52. chart.xs({
  53. 'data1': [200, 210, 350, 400, 600, 750],
  54. 'data2': [200, 210, 350, 400, 550, 750, 900]
  55. });
  56. }, 3000);
  57. </script>
  58. </body>
  59. </html>