gpt4 book ai didi

javascript - 我如何计算一个月的平均总数

转载 作者:行者123 更新时间:2023-11-29 06:27:58 24 4
gpt4 key购买 nike

Helo,我有表 daily_report 在下面显示列

report_id | peak_generation | pdate | plant_id

每一行代表特定植物产生的总能量(每天 7 株植物)。我有 1 年的数据电子表格(2014 年 1 月至 12 月)。我需要一个查询来绘制每月总的“平均”峰值发电量。我已经能够使用融合图绘制的是每月的总峰值生成(即总峰值生成 Y 轴相对于月份 X 轴)。我如何获得每月植物总数的平均值?为了清楚起见,下面是代码。

<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("Includes/FusionCharts.php");
include("Includes/DBConn.php");
?>
<HTML>
<HEAD>
<TITLE>
FusionCharts Free - Database Example
</TITLE>
<?php
//You need to include the following JS file, if you intend to embed the chart using JavaScript.
//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
?>
<SCRIPT LANGUAGE="Javascript" SRC="js/FusionCharts.js"></SCRIPT>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.text{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</HEAD>
<BODY>


<?php
//In this example, we show how to connect FusionCharts to a database.
//For the sake of ease, we've used an MySQL databases containing two
//tables.

// Connect to the DB
$link = connectToDB();


// Fetch all factory records
//$strQuery = "select * from daily_output";
//$result = mysql_query($strQuery) or die(mysql_error());


//Iterate through each factory
//if ($result) {
//
//Now create a second query to get details for this factory
$strQuery = "select SUM(peak_generation) as TotOutput, MONTHNAME (pdate) as MONTH FROM daily_report WHERE pdate BETWEEN '2015-01-01' AND '2015-12-30' GROUP BY MONTH (pdate)";
$result = mysql_query($strQuery) or die(mysql_error());

$strXML = "<graph caption='Total Peak Electricity Generated ---- 2015 Month by Month' numberSuffix='MW' xAxisName='Month' yAxisName='MegaWatts' decimalPrecision='0' formatNumberScale='0' yaxismaxvalue='5000'>";


while($row = mysql_fetch_array($result)) {
//Generate <set name='..' value='..' />
$strXML .= "<set name = '".$row['MONTH']."' value = '".$row['TotOutput']."' />";

//$strXML .="<set name ='" . datePart("d",$row['DAYS']) . "/" . datePart("m",$row['DAYS']) . "' value='" . $row['TotOutput'] . "'/>";
}
//Finally, close <graph> element
$strXML .= "</graph>";
//Create the chart - Pie 3D Chart with data from $strXML
//echo renderChart("charts/FCF_Column3D.swf", "", $strXML, "FactorySum", 650, 450);
echo renderChart("charts/FCF_Column3D.swf", "", $strXML, "annual_revenue", 1200, 500);


//free the resultset
mysql_free_result($result);


mysql_close($link);
?>




<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>


<CENTER></CENTER>
</BODY>
</HTML>

最佳答案

尝试使用 mysql 的 AVG()group by month 你应该得到输出。

您可以在此处查看教程:here

关于javascript - 我如何计算一个月的平均总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29768070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com