0

Hey im new to Canvas JS and was just wondering that whether for my data points' Y axis, can I collect the content from a text file in php, store the variable in JavaScript and print of this value as the Y axis for my data point. So in the example below, how would I use the content in this text file as the Y axis co-ordinates?

<!DOCTYPE HTML>
<html>
<head>
<?php
$DaveLogins = file_get_contents("NoLoginsDave.txt");
?>
<script type="text/javascript">
var val = "<?php echo $DaveLogins ?>";
//alert(val);
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
    theme: "light1",
    animationEnabled: true, 
    title:{
        text: "The Number of Logins Per User"
    },
    data: [
    {
        type: "column",
        dataPoints: [
            { label: "Lucy",  y: 10  },
            { label: "Dave", y: val  },
            { label: "Mike", y: 25  },
        ]
    }
    ]
});
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>

I was stuck on this issue and couldn't find nothing online. Any help would be appreciated.

Update: Ive tried to debug the program but still, couldnt find the issue. One way I know I have successfully transfered the datatype from both languages is by using the alert function to print of the value of "val". As I cant find a solution to this problem how should i approach this scenario?

0 Answers0