    <?php
    $dataPoints2021 = array();
    $dataPoints2020 = array();
    $dataPoints2019 = array();
    $dataPoints2018 = array();
    $dataPoints2017 = array();
    $dataPoints2016 = array();
    $dataPoints2015 = array();




//----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 6 year), ' ' , time)) as data2, t_out from history where date like '2021%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2021, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 5 year), ' ' , time)) as data2, t_out from history where date like '2020%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2020, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//-----------------------------------------------------------------------------------------------------------------------------------------

    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 4 year), ' ' , time)) as data2, t_out from history where date like '2019%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2019, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );


        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 3 year), ' ' , time)) as data2, t_out from history where date like '2018%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2018, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 2 year), ' ' , time)) as data2, t_out from history where date like '2017%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2017, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date_sub(date, interval 1 year), ' ' , time)) as data2, t_out from history where date like '2016%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2016, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));
        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
    try{
        $link = new \PDO(   'mysql:host=localhost;dbname=weather',
                            'weather',
                            'weather',
                            array(
                                \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                \PDO::ATTR_PERSISTENT => false
                            )
                        );

        $handle = $link->prepare("select unix_timestamp(concat(date, ' ' , time)) as data2, t_out from history where date like '2015%' and t_out > '-30' and t_out < '40' ");
        $handle->execute();
        $result = $handle->fetchAll(\PDO::FETCH_OBJ);

        foreach($result as $row){
            array_push($dataPoints2015, array("x"=> $row->data2 * 1000, "y"=> $row->t_out));

        }
        $link = null;
    }
    catch(\PDOException $ex){
        print($ex->getMessage());
    }
//-----------------------------------------------------------------------------------------------------------------------------------------
    ?>

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

    var chart = new CanvasJS.Chart("chartContainer", {
    	animationEnabled: true,
    	exportEnabled: true,
	zoomEnabled: true,
    	theme: "light1", // "light1", "light2", "dark1", "dark2"
    	title:{
    		text: "Weather data history"
    	},
	legend:{
		verticalAlign: "top",

		fontSize: 22,
	},
	axisX:{
		labelAngle: 45,
		valueFormatString: "D MMMM",
	},
        axisY:{
                minimum: -15,
                maximum: 40,
        },
    	data: [
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2021",
                showInLegend: true,
                legendText: "2021",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2021, JSON_NUMERIC_CHECK); ?>
                },
		{
    		type: "line", //change type to bar, line, area, pie, etc
		name: "2020",
	        showInLegend: true,
	        legendText: "2020",
                xValueType: "dateTime",
		xValueFormatString: "D MMMM, H:mm",
		dataPoints: <?php echo json_encode($dataPoints2020, JSON_NUMERIC_CHECK); ?>
    		},
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2019",
                showInLegend: true,
                legendText: "2019",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2019, JSON_NUMERIC_CHECK); ?>
                },
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2018",
                showInLegend: true,
                legendText: "2018",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2018, JSON_NUMERIC_CHECK); ?>
                },
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2017",
                showInLegend: true,
                legendText: "2017",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2017, JSON_NUMERIC_CHECK); ?>
                },
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2016",
                showInLegend: true,
                legendText: "2016",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2016, JSON_NUMERIC_CHECK); ?>
                },
                {
                type: "line", //change type to bar, line, area, pie, etc
                name: "2015",
                showInLegend: true,
                legendText: "2015",
                xValueType: "dateTime",
                xValueFormatString: "D MMMM, H:mm",
                dataPoints: <?php echo json_encode($dataPoints2015, JSON_NUMERIC_CHECK); ?>
                },
	]
    });
    chart.render();
    }
    </script>
    </head>
    <body>
    <div id="chartContainer" style="height: 900px; width: 95%;"></div>
    <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
    </body>
    </html>
