chart_bar.html 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <html>
  2. <head>
  3. <link href="/css/c3.css" rel="stylesheet" type="text/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. data: {
  12. columns: [
  13. ['data1', 1030, 1200, 1100, 1400, 1150, 1250],
  14. ['data2', 2130, 2100, 2140, 2200, 2150, 1850]
  15. // ['data1', 30, 200, 100, 400, 150, 250],
  16. // ['data2', 130, 100, 140, 200, 150, 50]
  17. ],
  18. type: 'bar',
  19. onclick: function (d, element) { console.log("onclick", d, element); },
  20. onmouseover: function (d) { console.log("onmouseover", d); },
  21. onmouseout: function (d) { console.log("onmouseout", d); }
  22. },
  23. axis: {
  24. x: {
  25. type: 'categorized'
  26. }
  27. },
  28. bar: {
  29. width: {
  30. ratio: 0.3,
  31. // max: 30
  32. },
  33. }
  34. });
  35. </script>
  36. </body>
  37. </html>