barFloating.html 2.83 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>amCharts examples</title>
        <link rel="stylesheet" href="style.css" type="text/css">
        <script src="../amcharts/amcharts.js" type="text/javascript"></script>
        <script src="../amcharts/serial.js" type="text/javascript"></script>
        <script type="text/javascript">
            var chart;

            var chartData = [
                {
                    "name": "John",
                    "startTime": 8,
                    "endTime": 11,
                    "color": "#FF0F00"
                },
                {
                    "name": "Joe",
                    "startTime": 10,
                    "endTime": 13,
                    "color": "#FF9E01"
                },
                {
                    "name": "Susan",
                    "startTime": 11,
                    "endTime": 18,
                    "color": "#F8FF01"
                },
                {
                    "name": "Eaton",
                    "startTime": 15,
                    "endTime": 19,
                    "color": "#04D215"
                }
            ];


            AmCharts.ready(function () {
                // SERIAL CHART
                chart = new AmCharts.AmSerialChart();
                chart.dataProvider = chartData;
                chart.categoryField = "name";
                chart.rotate = true;
                chart.columnWidth = 0.9;
                chart.startDuration = 1;

                // AXES
                // Category
                var categoryAxis = chart.categoryAxis;
                categoryAxis.gridAlpha = 0.1;
                categoryAxis.axisAlpha = 0;
                categoryAxis.gridPosition = "start";

                // Value
                var valueAxis = new AmCharts.ValueAxis();
                valueAxis.gridAlpha = 0.1;
                valueAxis.axisAlpha = 0;
                valueAxis.unit = ":00";
                chart.addValueAxis(valueAxis);

                // GRAPH
                var graph = new AmCharts.AmGraph();
                graph.valueField = "endTime";
                graph.openField = "startTime";
                graph.type = "column";
                graph.lineAlpha = 0;
                graph.colorField = "color";
                graph.fillAlphas = 0.8;
                graph.balloonText = "<b>[[category]]</b><br>starts at [[startTime]]:00<br>ends at [[endTime]]:00";
                chart.addGraph(graph);

                chart.creditsPosition = "top-right";

                // WRITE
                chart.write("chartdiv");
            });
        </script>
    </head>

    <body>
        <div id="chartdiv" style="width: 100%; height: 400px;"></div>
    </body>

</html>