 |
JpGraph Error กราฟแท่งครับ JpGraph Error: 25070 Either X or Y data arrays contains non-numeric values. Check that the data is really specified as numeric data and not as strings. |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php // content="text/plain; charset=utf-8"
require_once ('../jpgraph/src/jpgraph.php');
require_once ('../jpgraph/src/jpgraph_bar.php');
include"../connect.php";
$sql="SELECT * FROM evaluation WHERE project_id='4' ";
$query=mysql_query($sql);
while($datay=mysql_fetch_array($query)){
//$datay=array(12,8,38,3,10,5);
echo"$datay[score]<br>";
// Create the graph. These two calls are always required
$graph = new Graph(300,200);
$graph->SetScale('textlin');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,40,40);
// Create a bar pot
$bplot = new BarPlot('$datay[score]');
$graph->Add($bplot);
// Create and add a new text
$txt=new Text('ทดสอบ');
$txt->SetPos(10,20);
$txt->SetColor('darkred');
$txt->SetFont(FF_ANGSA,FS_BOLD,15);
$txt->SetBox('yellow','navy','[email protected]');
$graph->AddText($txt);
// Setup the titles
$graph->title->Set('ทดสอบ');
$graph->xaxis->title->Set('แกน-X');
$graph->yaxis->title->Set('แกน-Y');
$graph->title->SetFont(FF_ANGSA,FS_BOLD,18);
$graph->yaxis->title->SetFont(FF_ANGSA,FS_BOLD,18);
$graph->xaxis->title->SetFont(FF_ANGSA,FS_BOLD,18);
// Display the graph
$graph->Stroke();
}
?>
มันบอกประมาณว่าข้อมูลออกมาเป็นสตริง -..-* ในตารางนั้นผมเก็บ ตัวเลขไว้อ่ะครับ งง งิ
JpGraph Error: 25070 Either X or Y data arrays contains non-numeric values. Check that the data is really specified as numeric data and not as strings. It is an error to specify data for example as '-2345.2' (using quotes).
อันนี้ตารางครับ
project_id | score
4 7.5
4 15.69
4 10
4 20
4 18.75
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-04-17 22:37:12 |
By :
icute |
View :
2339 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php // content="text/plain; charset=utf-8"
require_once ('../jpgraph/src/jpgraph.php');
require_once ('../jpgraph/src/jpgraph_bar.php');
include"../connect.php";
$sql="SELECT * FROM evaluation WHERE project_id='4' ";
$query=mysql_query($sql);
$datay = array();
while($row = mysql_fetch_array($query)){
$datay[] = $row['score'];
}
//$datay=array(12,8,38,3,10,5);
// Create the graph. These two calls are always required
$graph = new Graph(300,200);
$graph->SetScale('textlin');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,40,40);
// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);
// Create and add a new text
$txt=new Text('ทดสอบ');
$txt->SetPos(10,20);
$txt->SetColor('darkred');
$txt->SetFont(FF_ANGSA,FS_BOLD,15);
$txt->SetBox('yellow','navy','[email protected]');
$graph->AddText($txt);
// Setup the titles
$graph->title->Set('ทดสอบ');
$graph->xaxis->title->Set('แกน-X');
$graph->yaxis->title->Set('แกน-Y');
$graph->title->SetFont(FF_ANGSA,FS_BOLD,18);
$graph->yaxis->title->SetFont(FF_ANGSA,FS_BOLD,18);
$graph->xaxis->title->SetFont(FF_ANGSA,FS_BOLD,18);
// Display the graph
$graph->Stroke();
?>
ตัวแปร $datay ต้องเป็นตัวแปร array ครับ
|
 |
 |
 |
 |
Date :
2010-04-17 22:59:12 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

Code connect.php (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php #บันทัดที่9
mysql_pconnect("localhost","root","123456");
mysql_select_db("project");
mysql_query("set names utf8");
?>
</body>
</html>
เป็นแบบนี้ อ่ะครับ
|
 |
 |
 |
 |
Date :
2010-04-17 23:14:12 |
By :
icute |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลบ แท็ก html ออกก็รันได้แหะ อยากรู้อ่ะครับว่าทำไม หรือไฟล์ connect.php ของผมเขียนแค่นี้ก็ได้ใช่มั้ยครับ
ผมใช้ดรีมเขียนด้วย>,.< ขอบคุณมากนะครับ
Code (PHP)
<?php #บันทัดที่9
mysql_pconnect("localhost","root","123456");
mysql_select_db("project");
mysql_query("set names utf8");
?>
|
 |
 |
 |
 |
Date :
2010-04-17 23:19:22 |
By :
icute |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
jpgraph จะ echo ออกเป็นข้อมูลไฟล์รูปภาพครับเวลาใส่
html หรือข้อความต่างๆ จะทำให้กลายเป็นรูปแบบไฟล์ภาพที่ไม่ถูกต้องครับ
|
 |
 |
 |
 |
Date :
2010-04-17 23:40:40 |
By :
:) |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณสำหรับความรู้ครับ
|
 |
 |
 |
 |
Date :
2010-04-17 23:48:26 |
By :
icute |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|