DEV Community

evidyasagar
evidyasagar

Posted on

Reading data from sql query and plot graph using reactjs

Hi All,

I have developed nodejs and reactjs code that pulls the data from mysql database in server.js file(at the backendside) and used useEffect hook to fetch the data from endpoint used in server.js to show the records from Database, using Line.js script. However, I am not able to show the selected data in the graph view on Line.js script which is attached for the reference for both scripts. Looking forward to your assistance. I will share the code snippet if required.

Snippet of server.js##
const db=mysql.createConnection({
connectionLimit : xxx,
waitForConnections : true,
queueLimit :0,
host: 'localhost',
user: 'root',
password:'XXXXXXX',
database: 'oamordersreport',
debug: true,
wait_timeout : xxxxx,
connect_timeout :xx
});
app.get('/maoorders', (req, res) => {
const sql = "SELECT * FROM oamorder";
db.query(sql, (err, data) =>{
if(err) return res.json("Error...");
return res.json(data);

line.js code snippet

function Line(){
const [data, setData] = useState([])
useEffect(() =>{
fetch('http://localhost:xxxx/oamorders')
//.then(res => res.json())
.then(data => setData(data))
.then(err => console.log(err));;
},[])
...

Top comments (0)