- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 PHP 脚本从 mysql 数据库中提取数据,并使用谷歌图表以图形方式显示数据。当使用只有 2 个变量要处理的饼图或条形图时,它工作得很好。现在我想使用 ComboChart。我在一个表中有 4 个字段:名称、日期、数量、成本。我想要一个 ComboChart,其中 x 轴是日期,条形图代表数量,折线图代表成本。
这是我目前的代码。我该怎么做呢?在 drawChart() 函数中,x 轴或 y 轴上的内容没有明确的顺序,所以我怎么知道我的哪些数据显示在哪里?这是否取决于您在 mysqli_query 期间选择数据的顺序?
// host, username, password and dbname are already declared
$conn = mysqli_connect($host, $username, $password);
if ($conn->connect_error) {
die("Could not connect: " . mysql_error()) . "<br>";
}
mysqli_select_db($conn, $dbname);
$qresult = mysqli_query($conn, "SELECT * FROM Scrap");
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'string'),
array('label' => 'Quantity', 'type' => 'number'),
array('label' => 'Cost', 'type' => 'number')
);
$rows = array();
while ($r = $qresult->fetch_assoc()) {
$temp = array();
$temp[] = array('v' => (string) $r['Date']);
// Values of each slice
$temp[] = array('v' => (int) $r['Quantity']);
$temp[] = array('v' => (float) $r['Cost']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
?>
<html>
<head>
<!--Load the Ajax API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
title: 'YTD Controllable Scrap Costs',
seriesType:'bars',
series:{2: {type: 'line'}}
// width: 800,
// height: 600
};
// Instantiate and draw our chart, passing in some options.
// Do not forget to check your div ID
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--this is the div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
最佳答案
所以我四处测试,发现第一列是 x 轴,第二、第三、第四等列在 y 轴上。条形图和折线图未显示的原因是因为在我的 drawChart() 函数中,它说:series:{2: {type: 'line'}}
,数字 2 指的是到 y 轴的第三个字段,因为它是零索引的。我没有 y 轴的第三个字段,所以我将其切换为 series:{1: {type: 'line'}}
现在我得到了一个条形图和一个折线图.
关于php - 如何使用 mysql 数据库中的数据创建 Google ComboChart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38751338/
大家好,目前正在使用组合图表,我正在尝试获取所有值的平均值并在图表上显示一条线来表示每个代理的平均值。 我进行了一些挖掘,我确实尝试使用一种资源,但它抛出了错误,我一直在努力寻找解决方案。 下面是一个
我正在使用gwt-visualization ( Chart Tools 周围的包装)。我有一个 ComboChart,其中包括两个条形图(堆叠)和一个折线图,我想向某些行添加 annotation
chart.draw(data,{ colors:[self.model.get("color"), '#FF0000'],
我在此处找到了我之前关于图表的问题的答案 fill background color horizontally in google line chart on specified area 现在我的问
我正在使用 PHP 脚本从 mysql 数据库中提取数据,并使用谷歌图表以图形方式显示数据。当使用只有 2 个变量要处理的饼图或条形图时,它工作得很好。现在我想使用 ComboChart。我在一个表中
我正在尝试获取堆积条形图。下面的示例应该堆叠 2017-W30 的两个值。相反,它在 x 轴上给了我两次 2017-W30。 我在选项中使用 isStacked 但它不起作用。 'options':
我看过 docs for combo charts并且能够将带有一条线的条形图重现为不同的系列。但是,我如何获得带有不同系列线条的烛台图表? 当我尝试时,出现错误 Last domain does n
一段时间以来,我一直在使用带有 ComboChart 的谷歌可视化图表,它一直在工作。 我没有改变任何东西,突然我在加载我的 ComboChart 时收到以下谷歌可视化错误消息:Cannot read
我是一名优秀的程序员,十分优秀!