doubingguan3425 2019-04-27 12:26
浏览 66

在PHP中读取文本文件,将此数据传输到Javascript并将此值表示为数据点

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?(The content inside of the text file is the number "7")

<!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>

The problem is that I am trying to represent the value inside of the text file as one of the co-ordinates for my data points. By calling this value in PHP and transferring this value over to JavaScript, I am not able to do this. When I run the code, the column for Dave isn't represented as a bar chart. I was thinking whether there was an alternative solution? Or am I doing something wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win c++ socket
    • ¥15 CanMv K210开发板实现功能
    • ¥15 C# datagridview 栏位进度
    • ¥15 vue3页面el-table页面数据过多
    • ¥100 vue3中融入gRPC-web
    • ¥15 kali环境运行volatility分析android内存文件,缺profile
    • ¥15 写uniapp时遇到的问题
    • ¥15 vs 2008 安装遇到问题
    • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
    • ¥15 找一个网络防御专家,外包的