axes_range.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="/css/c3.css">
  4. </head>
  5. <body>
  6. <div id="chart1"></div>
  7. <div id="chart2"></div>
  8. <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
  9. <script src="/js/c3.js"></script>
  10. <script>
  11. var chart1 = c3.generate({
  12. bindto: '#chart1',
  13. data: {
  14. columns: [
  15. ['sample', 100, 200, 100, 400, 150, 250]
  16. ],
  17. },
  18. axis: {
  19. x: {
  20. min: -10,
  21. max: 10,
  22. }
  23. },
  24. });
  25. var chart2 = c3.generate({
  26. bindto: '#chart2',
  27. data: {
  28. x: 'x',
  29. columns: [
  30. ['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'],
  31. ['sample', 100, 200, 100, 400, 150, 250]
  32. ],
  33. },
  34. axis: {
  35. x: {
  36. type: 'timeseries',
  37. min: new Date('2012-12-20'),
  38. max: '2013-03-01',
  39. tick : {
  40. format : "%Y-%m-%d %H:%M:%S" // https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-format
  41. }
  42. }
  43. }
  44. });
  45. setTimeout(function () {
  46. chart1.axis.max({x: 20});
  47. }, 1000);
  48. setTimeout(function () {
  49. chart1.axis.min({x: -5});
  50. }, 2000);
  51. setTimeout(function () {
  52. chart1.axis.range({max: {x: 5}, min: {x: 0}});
  53. }, 3000);
  54. setTimeout(function () {
  55. chart2.axis.max({x: new Date('2013-02-01')});
  56. }, 1000);
  57. setTimeout(function () {
  58. chart2.axis.min({x: new Date('2012-12-01')});
  59. }, 2000);
  60. setTimeout(function () {
  61. chart2.axis.range({max: {x: '2013-01-06'}, min: {x: '2013-01-01'}});
  62. }, 3000);
  63. setTimeout(function () {
  64. chart2.axis.max({y: 1000});
  65. }, 4000);
  66. setTimeout(function () {
  67. chart2.axis.min({y: -1000});
  68. }, 5000);
  69. setTimeout(function () {
  70. chart2.axis.range({max: {y: 400}, min: {y: 0}});
  71. }, 6000);
  72. </script>
  73. </body>
  74. </html>