Я пытаюсь сгенерировать график в php, используя набор данных. Это многолинейный график, т.е. у меня есть 3 оператора: GP, BL, ROBI. Я могу генерировать строки для двух операторов, но третья строка не генерируется для оператора.
Вот что я попробовал:
$smarty = new Smarty();
if($year == "")
{
$year="2014";
}
$strpaid = "SELECT DATE_FORMAT(sdate, '%Y-%m') AS tdate,operator,sum(total_revenue) AS TotalRevenue FROM tbl_revenue_opr GROUP BY operator,tdate";
//$strfree = "SELECT sum(total_revenue) AS TotalRevenue, DATE_FORMAT(sdate, '%Y-%m') AS tdate FROM funstore_mis.tbl_revenue_opr GROUP BY tdate";
//echo $strpaid; echo $strfree; exit;
$resultpaid = mysql_query($strpaid) or die('Error:'.mysql_error());
//$year = "2012";
$year1 = $year."-01";
$year2 = $year."-02";
$year3 = $year."-03";
$year4 = $year."-04";
$year5 = $year."-05";
$year6 = $year."-06";
$year7 = $year."-07";
$year8 = $year."-08";
$year9 = $year."-09";
$year10 = $year."-10";
$year11 = $year."-11";
$year12 = $year."-12";
$c1 = "0099FF";
$c2 = "FF8000";
$c3 = "008000";
$c4 = "FB8000";
//$File2 = "downloadsmanth.xml";
//$Handle2 = fopen($File2, 'w');
$manthXML ="<graph caption='Total Revenue' xAxisName='Month' yAxisName='Revenue' bgColor='F1f1f1' showLegend='1' decimalPrecision='0' showNames='1' showValues='1' pieFillAlpha='70' pieSliceDepth='15' pieRadius='100' baseFontSize='12' rotateNames='1' formatNumberScale='0'>";
$manthXML .="<categories>";
$manthXML .="<category name='Jan' />";
$manthXML .="<category name='Feb' />";
$manthXML .="<category name='Mar' />";
$manthXML .="<category name='Apr' />";
$manthXML .="<category name='May' />";
$manthXML .="<category name='Jun' />";
$manthXML .="<category name='Jul' />";
$manthXML .="<category name='Aug' />";
$manthXML .="<category name='Sep' />";
$manthXML .="<category name='Oct' />";
$manthXML .="<category name='Nov' />";
$manthXML .="<category name='Dec' />";
$manthXML .="</categories>";
$opname = "1";
$opname1 = "1";
$i=1;
while($row = mysql_fetch_array($resultpaid))
{
if($opname1 != "1")
{
$opname = $row["operator"];
}
//echo $opname;
//echo $opname1;
if($opname != $opname1)
{
$clr = "c".$i;
$manthXML .="<dataset seriesname='".$opname1."' color='".$$clr."' showValue='1' alpha='100' anchorAlpha='0' lineThickness='2'>";
$manthXML .="<set value='".$janVal."' />";
$manthXML .="<set value='".$febVal."' />";
$manthXML .="<set value='".$marVal."' />";
$manthXML .="<set value='".$aprVal."' />";
$manthXML .="<set value='".$mayVal."' />";
$manthXML .="<set value='".$junVal."' />";
$manthXML .="<set value='".$julVal."' />";
$manthXML .="<set value='".$augVal."' />";
$manthXML .="<set value='".$sepVal."' />";
$manthXML .="<set value='".$octVal."' />";
$manthXML .="<set value='".$novVal."' />";
$manthXML .="<set value='".$decVal."' />";
$manthXML .="</dataset>";
$janVal=0;
$febVal=0;
$marVal=0;
$aprVal=0;
$mayVal=0;
$junVal=0;
$julVal=0;
$augVal=0;
$sepVal=0;
$octVal=0;
$novVal=0;
$decVal=0;
$i = $i + 1;
}
if($row["tdate"] == $year1)
{
$janVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year2)
{
$febVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year3)
{
$marVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year4)
{
$aprVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year5)
{
$mayVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year6)
{
$junVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year7)
{
$julVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year8)
{
$augVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year9)
{
$sepVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year10)
{
$octVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year11)
{
$novVal = $row["TotalRevenue"];
}
if($row["tdate"] == $year12)
{
$decVal = $row["TotalRevenue"];
}
$opname1 = $row["operator"];
}
$totalpaid = $janVal+$febVal+$marVal+$aprVal+$mayVal+$junVal+$julVal+$augVal+$sepVal+$octVal+$novVal+$decVal;
$totalpaidavg = ($totalpaid/$avg);
$manthXML .='</graph>';
Пожалуйста, скажите, где я иду не так! Спасибо !!
Проверьте, выбирается ли набор данных ROBI и генерируется ли набор данных. Попробуйте вывести «$ manthXML» перед отображением диаграммы.
Других решений пока нет …