我正在内部CRM中为管理信息中心创建图表,但是我在添加趋势线时遇到了一些麻烦。我似乎无法找到内置函数的任何文档,所以试图使用一个笨重而缓慢的SQL查询来完成它。
SELECT days.date,
(SELECT count(app.app_id) FROM li_appointments.li_appointments as app
where app_datetime >= date_add(days.date, interval -7 day)
and app_datetime <= days.date) / 5 as average
FROM li_appointments.li_days as days
where date >= date_add(date(now()), interval -30 day)
and date <= date(now())
只需12秒就可以获取图表中这一行的数据。是否有任何本地方法使用pChart执行此操作,还是有更好的PHP选项可用?
以下是我现在使用的完整代码,没有趋势线:
$getapps = "SELECT days.date, app.app_id as scheduled
,cnc.app_id as cnc
,dnc.app_id as dnc
,cancel.app_id as cancel
,covered.app_id as covered
FROM li_appointments.li_days as days
left Join (SELECT date(app_datetime) as app_datetime
, count(app_id) as app_id
FROM li_appointments.li_appointments
group by date(app_datetime))
as app on days.date = app.app_datetime
left Join (SELECT date(app_datetime) as app_datetime
, count(app_id) as app_id
FROM li_appointments.li_appointments
Where app_id in (select app_id from li_app_cnc)
group by date(app_datetime))
as cnc on days.date = cnc.app_datetime
left Join (SELECT date(app_datetime) as app_datetime
, count(app_id) as app_id
FROM li_appointments.li_appointments
Where app_id in (select app_id from li_app_dnc)
group by date(app_datetime))
as dnc on days.date = dnc.app_datetime
left Join (SELECT date(app_datetime) as app_datetime
, count(app_id) as app_id
FROM li_appointments.li_appointments
Where app_id in (select app_id from li_app_canceled)
group by date(app_datetime))
as cancel on days.date = cancel.app_datetime
left Join (SELECT date(app_datetime) as app_datetime
, count(app_id) as app_id
FROM li_appointments.li_appointments
Where terp_id is not null and terp_id <> ''
group by date(app_datetime))
as covered on days.date = covered.app_datetime
Where date > adddate(now(), Interval -30 day)
and date <= date(now())
group by date";
$result = mysql_query($getapps );
$date = array();
$scheduled = array();
$cnc = array();
$dnc = array();
$canceled = array();
$covered = array();
while($row = mysql_fetch_array($result)){
array_push($date, $row['date']);
array_push($scheduled, $row['scheduled']);
array_push($cnc, $row['cnc']);
array_push($dnc, $row['dnc']);
array_push($canceled, $row['cancel']);
array_push($covered, $row['covered']);
}
/* CAT:Line chart */
/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php");
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($scheduled,"Scheduled");
$MyData->addPoints($cnc,"CNC");
$MyData->addPoints($dnc,"DNC");
$MyData->addPoints($canceled,"canceled");
$MyData->addPoints($covered,"covered");
$MyData->setSerieTicks("Probe 2",4);
$MyData->setSerieTicks("Probe 3",4);
$MyData->setAxisName(0,"Appointments");
$MyData->addPoints($date,"Labels");
$MyData->setSerieDescription("Labels","Months");
$MyData->setAbscissa("Labels");