api_zoom.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. columns: [
  14. generateData(100)
  15. ],
  16. },
  17. zoom: {
  18. enabled: true,
  19. initialRange: [30, 60],
  20. onzoomstart: function (event) {
  21. console.log("onzoomstart", event);
  22. },
  23. onzoom: function (domain) {
  24. console.log("onzoom", domain);
  25. },
  26. onzoomend: function (domain) {
  27. console.log("onzoomend", domain);
  28. },
  29. },
  30. subchart: { show: true }
  31. });
  32. function generateData(n) {
  33. var column = ['sample'];
  34. for (var i = 0; i < n; i++) {
  35. column.push(Math.random() * 500);
  36. }
  37. return column;
  38. }
  39. // with subchart
  40. setTimeout(function () {
  41. chart.zoom([45,75]);
  42. }, 1000);
  43. setTimeout(function () {
  44. chart.zoom([25,90]);
  45. }, 2000);
  46. setTimeout(function () {
  47. chart.unzoom();
  48. }, 3000);
  49. // without subchart
  50. setTimeout(function () {
  51. chart.internal.config.subchart_show = false;
  52. chart.flush();
  53. }, 4000);
  54. setTimeout(function () {
  55. chart.zoom([45,75]);
  56. }, 5000);
  57. setTimeout(function () {
  58. chart.zoom([25,90]);
  59. }, 6000);
  60. setTimeout(function () {
  61. chart.unzoom();
  62. }, 7000);
  63. </script>
  64. </body>
  65. </html>