vis.js條形圖

DogLeftover發表於2024-04-22
  • 程式碼案例
<!doctype html>
<html>
<head>
  <title>Timeline</title>
  <script type="text/javascript" src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>
  <link href="https://unpkg.com/vis-timeline@latest/styles/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
    body,
    html {
        font-family: sans-serif;
    }
    #visualization {
        width: 600px;
    }
  </style>
</head>
<body>

<div id="visualization"></div>
    
<script type="text/javascript">
    var container = document.getElementById("visualization");
    var items = [
    { x: "2014-06-11", y: 10 },
    { x: "2014-06-12", y: 25 },
    { x: "2014-06-13", y: 30 },
    { x: "2014-06-14", y: 10 },
    { x: "2014-06-15", y: 15 },
    { x: "2014-06-16", y: 30 },
    ];

    var dataset = new vis.DataSet(items);
    var options = {
    style: "bar",
    barChart: { width: 50, align: "center" }, // align: left, center, right
    drawPoints: false,
    dataAxis: {
        icons: true,
    },
    orientation: "top",
    start: "2014-06-10",  // 開啟後預設顯示的區間
    end: "2014-06-18",
    };
    var graph2d = new vis.Graph2d(container, items, options);

</script>
</body>
</html>
  • 效果圖
點選檢視詳情

相關文章