timeseries_date.html 2.0 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="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. bindto: '#chart',
  12. data: {
  13. x : 'x',
  14. xFormat : '%Y%m%d',
  15. columns: [
  16. ['x', new Date('2013-01-01T00:00:00Z'), new Date('2013-01-02T00:00:00Z'), new Date('2013-01-03T00:00:00Z'), new Date('2013-01-04T00:00:00Z'), new Date('2013-01-05T00:00:00Z'), new Date('2013-01-06T00:00:00Z')],
  17. ['sample', 30, 200, 100, 400, 150, 250],
  18. ['sample2', 130, 300, 200, 450, 250, 350]
  19. ]
  20. },
  21. axis : {
  22. x : {
  23. type : 'timeseries',
  24. tick : {
  25. // format : "%m/%d" // https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-format
  26. format : "%e %b %y" // https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-format
  27. }
  28. }
  29. }
  30. });
  31. setTimeout(function () {
  32. chart.load({
  33. columns: [
  34. ['sample', 200, 130, 90, 240, 130, 100],
  35. ['sample2', 300, 200, 160, 400, 250, 250]
  36. ]
  37. });
  38. }, 1000);
  39. setTimeout(function () {
  40. chart.load({
  41. columns: [
  42. ['x', '20140101', '20140201', '20140301', '20140401', '20140501', '20140601'],
  43. ['sample', 500, 630, 690, 440, 630, 900],
  44. ['sample2', 400, 600, 460, 200, 350, 450]
  45. ]
  46. });
  47. }, 2000);
  48. setTimeout(function () {
  49. chart.load({
  50. columns: [
  51. ['x', new Date('2014-01-02T00:00:00Z'), new Date('2014-02-02T00:00:00Z'), new Date('2014-03-02T00:00:00Z'), new Date('2014-04-02T00:00:00Z'), new Date('2014-05-02T00:00:00Z'), new Date('2014-06-02T00:00:00Z')],
  52. ['sample', 500, 630, 690, 440, 630, 900],
  53. ['sample2', 400, 600, 460, 200, 350, 450]
  54. ]
  55. });
  56. }, 3000);
  57. </script>
  58. </body>
  59. </html>