我想在图表中显示我的表格的值,但我不知道从哪里开始。有没有教程如何做到这一点?我试着和我一起寻找同样的问题希望找到任何解决方案,但我没有得到任何
答案 0 :(得分:0)
我建议您使用Google charts:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
然后通过进行数据库查询或从文件读取来更改值。
例如,如果我们放大drawChart()
函数:
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
<?php
for ($i = 2004; $i < 2008; $i++) {
$dataSet .= '[\'' . $i . '\', ' . rand(100, 1500). ', ' . rand(100,500) . '],';
}
echo substr($dataSet, 0, -1); //remove the last ,(comma) from array
?>
]);