2011-08-14 3 views
1

내 테이블 "사용자"에 7 개의 열이 있습니다. 열은 다음과 같이이다 : 당신이 볼 수 있듯이, 나는 data:[]ac#를 삽입해야다른 날의 데이터 가져 오기

xAxis: { 
categories: ['Today', 'Yesterday', '12-08', '11-08','10-08','09-08','08-08'] 
}, 
series: [{ 
name: 'Clicks', 
data: [1,4,5,2,6,4,6] 
}] 

:

ac0 // Represents clicks made today 
ac1 // Represents clicks made from ac0 
ac2 // Represents clicks made from ac1 
ac3 // Represents clicks made from ac2 
ac4 // Represents clicks made from ac3 
ac5 // Represents clicks made from ac4 
ac6 // Represents clicks made from ac5 

I 차트에서 이것을 보여주고 있고, 그 다음과 같이 구축이다 필드에 입력 한 다음 각각에 날짜를 추가하여 categories:[]에 삽입하십시오.

어떻게 얻을 수 있습니까?

+0

어떤 코드를 시도 했습니까? –

+0

의심의 여지가 없으므로 지금까지 아무도 없습니다. –

+0

ac1 데이터가 어제 또는 tomorow에서 왔는지, ac2가 오늘부터 2 일 전인지, 2 일 후인지 등을 알 수 있습니다. –

답변

0

경우 : 여기 graph generated by pchart

위의 그래프를 생성 한 코드를 당신은 "카테고리"와 "데이터"를 채우기 만하면됩니다.

<?php 
    mysql_connect('localhost', 'root', ''); 
    $link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error()); 
    mysql_select_db('test') or die('Could not select database'); 

    // Performing SQL query 
    $query = 'SELECT ac0, ac1, ac2, ac3, ac4, ac5, ac6 FROM users WHERE id = 1'; 
    $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 

    while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
    { 
     $data = $row; 
    } 

    $days = array('Today', 'Yesterday'); 
    for ($i=2; $i<7;$i++) 
    { 
     $days[$i] = date('d-m', strtotime('-'.$i.' day')); 
    } 
?> 
xAxis: { 
categories: ['<?php echo implode("', '", $days); ?>'] 
}, 
series: [{ 
name: 'Clicks', 
data: [<?php echo implode(',', $data)?>] 
}] 
+0

고마워! 이 작동합니다. 하지만 ac0이 TODAYS 회를 나타 내기 때문에 $ i + 1을 $ i + 0으로 변경했습니다. 다시 한번 감사드립니다. –

+0

예, 맞았습니다. "+0"일을 삭제하고 "$ i"로 남겨 둘 수 있습니다. 답변을 업데이트 중입니다. –

0

당신은 당신이 pChart2, 그래프를 생성하는 PHP 라이브러리를 사용할 수있는 그래프가있는 IMG 생성해야하는 경우 :

<?php 
    mysql_connect('localhost', 'root', ''); 

    $link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error()); 

    mysql_select_db('test') or die('Could not select database'); 

    // Performing SQL query 
    $query = 'SELECT ac0, ac1, ac2, ac3, ac4, ac5, ac6 FROM users WHERE id = 1'; 
    $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 


    while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
    { 
     $data = $row; 
    } 

    // Free resultset 
    mysql_free_result($result); 

     // Closing connection 
    mysql_close($link); 

    // include pChart library 
    include("pchart/class/pData.class.php"); 
    include("pchart/class/pDraw.class.php"); 
    include("pchart/class/pImage.class.php"); 

    $MyData = new pData(); 
    // Add point to the graph 
    $MyData->addPoints($data, "clicks"); 

    // Configure Axis labels 
    $MyData->setAxisName(0, "Clicks"); 
    $MyData->addPoints(array('Today', 'Yesterday', '12-08', '11-08', '10-08', '09-08', '08-08'), "Labels"); 
    $MyData->setSerieDescription("Labels", "Days"); 
    $MyData->setAbscissa("Labels"); 

    // Generate bar chart 
    $myPicture = new pImage(700, 230, $MyData); 
    $myPicture->setGraphArea(60, 60, 600, 200); 
    $myPicture->drawScale(array("DrawSubTicks" => TRUE)); 
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); 
    $myPicture->setFontProperties(array("FontName" => "pchart/fonts/verdana.ttf", "FontSize" => 6)); 
    $myPicture->setShadow(FALSE); 
    $myPicture->drawBarChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_MANUAL, "DisplayR"=>0, "DisplayG"=>0,"DisplayB"=>0, "Rounded" => TRUE, "Surrounding" => 60)); 

    /* Render the picture (choose the best way) */ 
    $myPicture->render("img/mygraph.png"); 

    echo '<img src="img/mygraph.png" />';