我有javascript函数我需要在页面(正文)中显示数据。我需要在图表和标题文本中显示值。如何在单独的div中显示身体部位的PH值。在小提琴中共享我的代码
https://jsfiddle.net/sahxyx0n/
@section scripts{
<script>
FusionCharts.ready(function () {
LoadChart();
});
function LoadChart() {
$.ajax({
url: '@Url.Action("get", "pond")',//remote api address
type: 'GET',
crossDomain: true,
success: function (data) {
if (data.success) {
var PHValue = data.sensorsdata.PH;
var phfusioncharts = new FusionCharts({
type: 'angulargauge',
renderAt: 'ph-container',
width: '450',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "PH Value ",
"lowerLimit": "0",
"upperLimit": "14",
"showValue": "1",
"valueBelowPivot": "1",
"theme": "fint"
},
"colorRange": {
"color": [{
"minValue": "0",
"maxValue": "5",
"code": "#e44a00"
}, {
"minValue": "5",
"maxValue": "10",
"code": "#f8bd19"
}, {
"minValue": "10",
"maxValue": "14",
"code": "#6baa01"
}]
},
"dials": {
"dial": [{
"value": PHValue
}]
}
}
});
}
}
});
}
</script>
}
答案 0 :(得分:1)
在你的功能中
.......
if (data.success) {
var PHValue = data.sensorsdata.PH;
$('#phValue').text(PHValue);
.....
.....
在你的html页面中添加这个,你要在哪里显示PHValue,
<div id="phValue"></div>
答案 1 :(得分:0)
这就是你想要的吗?
function doInit(){
//alert("Inside doInit() method");
let time = new Date();
let timePlaceHolder = document.getElementById("timePlaceHolder");
timePlaceHolder.innerHTML = "Current Time is: "+time;
}
window.addEventListener("load",doInit,false);
<!DOCTYPE html>
<html>
<head>
<title>Display JS Time</title>
<script type="text/javascript" src="only_one_time.js"></script>
</head>
<body>
<div id="timePlaceHolder"></div>
</body>
</html>