这是我写的统计曲线实例。欢迎交流。
if (!isset($_SESSION['ywclusername']))//判断是否登录
{
header("location:../../login.php");
exit;
}
?>
include("../../configywcl.php");
$xzapi=$jc;//大气监测站传值
$sqlgroups="select rq,nian,yue,ri,$xzapi from xzdq order by rq";
//echo $sqlgroups;
$resultgroups=mysql_query($sqlgroups);
$numrows=mysql_num_rows($resultgroups);
if ($numrows>0)
{
while($data=mysql_fetch_array($resultgroups))
{
$count++;
$nian=$data['nian'];
$yue=$data['yue']-1;
$ri=$data['ri'];
$api=$data["$xzapi"];
$rq="{date: new Date($nian,$yue,$ri),api:$api}";
//echo "$rq";
//$rq=$nian.','.$yue.','$ri;
if ($count
{
$shuju=$shuju."$rq,";
}
else
{
$shuju=$shuju."$rq";
}
}
}
$shuju="[$shuju];";
//echo $shuju;
?>
<?php echo $dqjcd;?>PM10质量曲线var chart;
var chartData = [];
var chartCursor;
var average = 100;
AmCharts.ready(function () {
// generate some data first
generateChartData();
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "../amcharts/images/";
chart.zoomOutButton = {
backgroundColor: '#000000',
backgroundAlpha: 0.15
};
chart.dataProvider = chartData;
chart.categoryField = "date";
// listen for "dataUpdated" event (fired when chart is rendered) and call zoomChart method when it happens
chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
categoryAxis.dashLength = 1;
categoryAxis.gridAlpha = 0.15;
categoryAxis.axisColor = "#DADADA";
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0.2;
valueAxis.dashLength = 1;
chart.addValueAxis(valueAxis);
// GUIDE for average
var guide = new AmCharts.Guide();
guide.value = average;
guide.lineColor = "#aa0000";
guide.dashLength = 4;
guide.label = "二级";
guide.inside = true;
guide.lineAlpha = 4;
valueAxis.addGuide(guide);
// GRAPH
var graph = new AmCharts.AmGraph();
graph.title = "空气质量曲线";
graph.valueField = "api";
graph.bullet = "round";
graph.bulletBorderColor = "#FFFFFF";//统计图边的颜色
graph.bulletBorderThickness = 2;
graph.lineThickness = 2;
graph.lineColor = "#0000aa";//折线颜色
graph.negativeLineColor = "#0352b5";
graph.hideBulletsCount = 50; // this makes the chart to hide bullets when there are more than 50 series in selection
chart.addGraph(graph);
// CURSOR 鼠标手势
chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorPosition = "mouse";
chart.addChartCursor(chartCursor);
// SCROLLBAR 上部-滚动选择条
var chartScrollbar = new AmCharts.ChartScrollbar();
chartScrollbar.graph = graph;
chartScrollbar.scrollbarHeight = 40;
chartScrollbar.color = "#ffffff";
chartScrollbar.autoGridCount = true;
chart.addChartScrollbar(chartScrollbar);
// WRITE
chart.write("chartdiv");
});
// 赋值
function generateChartData() {
chartData=<?php echo $shuju;?>;
}
// this method is called when chart is first inited as we listen for "dataUpdated" event
function zoomChart() {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
}
// changes cursor mode from pan to select
function setPanSelect() {
if (document.getElementById("rb1").checked) {
chartCursor.pan = false;
chartCursor.zoomable = true;
} else {
chartCursor.pan = true;
}
chart.validateNow();
}
|
选择
拖拽
include("../../foot.php")
?>