0
我想在我的谷歌折线图中显示更多小数点。此时图表不显示小数点后的数字。我希望图表显示2或3位小数。Google charts更多小数点
这是我的代码:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "Lat.php",
dataType:"json",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 600, height: 400});
}
</script>
</head>
<body>
<!--Div that will hold the chart-->
<div id="chart_div"></div>
</body>
</html>
图显示数据库中的数据,我呼吁这个数据与此代码:
<?php
$databaseName = "pws";
$con = mysql_connect('localhost', 'root', 'usbw') or die('Error connecting to server');
mysql_select_db($databaseName, $con);
$query = mysql_query('SELECT * FROM gpx');
$table = array();
$table['cols'] = array(
array('label' => 'id', 'type' => 'number'),
array('label' => 'Lat', 'type' => 'number'),
array('label' => 'Lon', 'type' => 'number'),
array('label' => 'Ele', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$temp = array();
$temp[] = array('v' => (int)$r['id']);
$temp[] = array('v' => (int) $r['Lat']);
$temp[] = array('v' => (int) $r['Lon']);
$temp[] = array('v' => (int) $r['Ele']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo $jsonTable;
?>
有谁知道我怎样才能使线路图显示更多小数?
编辑: 没关系,我设法解决它。 的(INT)的在PHP文件是问题,通过消除他们的问题解决了
无法理解您的问题,折线图根据您提供的数据进行渲染。如果你的数据有小数,你需要确保PHP脚本正确地格式化为有两个小数点,并且图表库会适当地渲染它。 我建议使用结构和示例数据来修改Google图表JSFiddle,以测试您是否能够在您的环境中未经测试而实现所需内容。如果可能的话,创建自己的小提琴并分享它,以更详细地描述问题。 http://jsfiddle.net/api/post/library/pure/ – 2014-12-13 11:16:34
我设法找到问题,我只需要在PHP文件中删除(int)的。现在它工作正常。谢谢你的帮助。 – 2014-12-13 12:29:09
很高兴看到这一点,我怀疑你的PHP代码可能会剥离小数。请更新您的问题或提供答案并接受它来解决问题。 – 2014-12-13 12:36:47