<?php
include 'conexao.php';

$dataPoints = array();
$sql_investimentos_empresa = $sqli->query("SELECT * FROM investimentos_empresa WHERE id_empresa='".$_GET['id']."' AND deleted_at IS NULL ORDER BY ano ASC");
while($row_investimentos_empresa = $sql_investimentos_empresa->fetch_assoc()) {

    array_push($dataPoints,
        array(
            "label" => $row_investimentos_empresa['ano'],
            "y" => $row_investimentos_empresa['valor']
        )
    );

}
?>
<!DOCTYPE HTML>
<html>
<head>
    <script>
        window.onload = function () {

            var chart = new CanvasJS.Chart("chartContainer", {
                animationEnabled: true,
                theme: "light2",
                backgroundColor: "#efefef",
                title:{
                    text: "Histórico de Investimentos",
                    fontSize: 30
                },
                axisX:{
                    labelFontSize: 15,
                    interval: 1,
                    intervalType: "year",
                    crosshair: {
                        enabled: true,
                        snapToDataPoint: true
                    }
                },
                axisY:{
                    title: "Valores em Reais",
                    includeZero: true,
                    prefix: "R$ ",
                    crosshair: {
                        enabled: true,
                        snapToDataPoint: true
                    }
                },
                toolTip:{
                    enabled: true
                },
                data: [{
                    type: "line",
                    yValueFormatString: "R$ #,##0.00",
                    dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
                }]
            });
            chart.render();

        }
    </script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
