timeseries.html 1.6 KB

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