Тёмный

How to Render Dynamic Data Using An API In ChartJS & React Hooks 

Arslan
Подписаться 7 тыс.
Просмотров 55 тыс.
50% 1

Опубликовано:

 

22 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 149   
@thecoolestguyeverer
@thecoolestguyeverer 4 года назад
Great Video!!! Something I've been looking for is how to update dynamic GraphJS charts with live feed API data from an http request onto a line chart. By this I mean sensor data or stock price data that could be called on a setInterval function to update. It surprises me that this is so hard to find because I can't imagine using static data like most tutorials teach in real life situations. I wouldn't want to create more work for you, but if you are looking for more chartJS React tutorial ideas, I think that it would benefit a lot of people and you would be the only one with a video on it.
@arslan99
@arslan99 4 года назад
I've been looking into that for a while I haven't even been able to figure it out yet but that video is definitely in the books to be made soon
@thecoolestguyeverer
@thecoolestguyeverer 4 года назад
@@arslan99 Luckily I just figured it out now. The answer was websockets. Inside of a componentDidMount block, I opened a websocket that essentially adds a value and then executes this.setState. works pretty great! Still a few kinks, but essentially the answer is websockets.
@arslan99
@arslan99 4 года назад
Oh that's really good to know I really only thought websockets would be good for like chat apps an stuff but to hear that charts could be updated live with websockets is cool use
@sagarbhatt5653
@sagarbhatt5653 3 года назад
Thank you @Arslan. This is what I was looking for so long. Much appreciate it.
@khoilam7569
@khoilam7569 3 года назад
Supper supper easy when you explained. Thanks so alot
@tuantranvan8807
@tuantranvan8807 3 года назад
thank you so much .
@romimaximus
@romimaximus 3 года назад
Awesome tutorial Arslan !!! , but i have a question ?...The values of the employees salaries amounts are not ordered by "ascending" or "descending" on the API, so does the chart do it automatically ?
@arslan99
@arslan99 3 года назад
I'm not too sure. Since I only pulled the data straight from the api and showed it. You can create a function that can do that and re arrange the order from ascending or descending
@romimaximus
@romimaximus 3 года назад
@@arslan99 ...thank you very much...👍
@emiliod90
@emiliod90 3 года назад
Great tutorial bro! Next Idea would be updating data and chart (perhaps via polling or webhook?)
@arslan99
@arslan99 3 года назад
I've never worked with webhooks before so maybe in the future but good idea tho
@Mangko
@Mangko 3 года назад
If you're using a local api for development (api address is localhost:.. etc.) you'll likely have an issue where CORS, just create a new shortcut anywhere, point it to Chrome and then add some of these options to the end "[PATH_TO_CHROME]\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp That worked for me, not sure if it's the best way but I hope it helps! :)
@Mangko
@Mangko 3 года назад
also, if there's a better way please let me know! :D
@arslan99
@arslan99 Год назад
unfortunetly im not too sure sorry
@IdonotwantaUtubename
@IdonotwantaUtubename 4 года назад
Hey thank you for the tutorial, I have a question. We didn't use the [employeeSalary, setEmployeeSalary] and the [employeeAge, setEmployeeAge] . So why did you define them in the beginning?
@arslan99
@arslan99 4 года назад
I was going to use them in the beginning but I completely forgot about em 🤦‍♂️
@roshanaktaleshi2726
@roshanaktaleshi2726 2 года назад
I need help! I wrote the code the same as you but I got "TypeError: Cannot read properties of undefined (reading 'map')" !! and I don't know what can I do!
@arslan99
@arslan99 2 года назад
Console log it without the map and see if you have the array of objects even available
@ammarahmed8155
@ammarahmed8155 3 года назад
Hey man, love the content, but could you do a video on updating the charts with data once they're already rendered? For example, an input form that pushes a new data point and then the chart updates? I've been looking everywhere but can't find a video on it.
@xskrish
@xskrish 3 года назад
did you manage to find it? I'm still looking!
@slookify
@slookify 2 года назад
thats what I came here for :D
@arslan99
@arslan99 Год назад
hmmm, I'm thinking you can use a useeffect hook to do that but I'll have to try it out on my own to asnwer your question properly sorry
@jll9464
@jll9464 2 года назад
Thank you for the video!!!
@arslan99
@arslan99 2 года назад
Np
@startFromNull
@startFromNull 3 года назад
thanks,, u saved my work
@fernandorofe
@fernandorofe 4 года назад
Great video! How did you remove the background grid from the chart?
@arslan99
@arslan99 4 года назад
I cover how to do it in this video at 6:04 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-A5KaLpqzRi4.html Hope this helps 🙂
@fernandorofe
@fernandorofe 4 года назад
@@arslan99 Tks. Your tutorial is helping me a lot. Only now at the end is the API "dummy.restapiexample.com/api/v1/employees" showing this error 👉"has been blocked by CORS policy:" I'm looking for another one to test, if you know of any, I'll be grateful if you share. Congratulations on the video! 🙌
@arslan99
@arslan99 4 года назад
@@fernandorofe github.com/axios/axios/issues/853#issuecomment-322954804 this github forum issue should help thats how i fixed mine also you can get the cors npm package and use that as the header hope this helps:)
@fernandorofe
@fernandorofe 4 года назад
@@arslan99 Thanks
@melissatermin5551
@melissatermin5551 3 года назад
it was a very helpfull video, thank you very much
@arslan99
@arslan99 3 года назад
I'm glad it helped ya out
@AndrewHilseberg
@AndrewHilseberg 2 года назад
awesome video! very helpful!
@arslan99
@arslan99 2 года назад
I'm glad you liked it 😃
@amandixit2389
@amandixit2389 3 года назад
Thank you so much for this awesome content. You saved my final year project man
@arslan99
@arslan99 Год назад
Happy to help!
@sudhakarb2896
@sudhakarb2896 2 года назад
Really Helpfull
@arslan99
@arslan99 2 года назад
I'm glad it helped ☺️
@ashtikhan2585
@ashtikhan2585 3 года назад
I am paasing data from parent component to child component as props child component is pie chart. First time data is uploading properly but on data update in parent component is not reflecting in child component. May I know. Why I am facing this issue. Is data update in pie chart not possible after render.
@arslan99
@arslan99 Год назад
I'm not too sure I'm sorry
@shelroythomas3707
@shelroythomas3707 3 года назад
When the data from the API changes, will your chart update without having to refresh the page?
@arslan99
@arslan99 3 года назад
I don't think so you'll have to implement a method to check if new data is added
@bethealphaa
@bethealphaa 4 года назад
Thanks for this video. Please upload similar content like that for different charts,pie.
@arslan99
@arslan99 4 года назад
If you want to try different charts just replace the imports with what you want
@bethealphaa
@bethealphaa 4 года назад
@@arslan99 It worked for me. Thank You. Also, can u upload more dynamic Dashboards with dynamic data display.
@arslan99
@arslan99 4 года назад
Yeah I'll consider it. It just takes a while to come up with an idea to make something dynamic :P
@willturner3440
@willturner3440 3 года назад
This is what I was looking for, thanks dude
@adityapuranik8469
@adityapuranik8469 3 года назад
Exactly what I was looking for, thanks man!
@deepakm5947
@deepakm5947 4 года назад
this is what i'm looking for man, thank you so much for this Dynamic data rendering in Charts
@arslan99
@arslan99 4 года назад
Np
@noura4086
@noura4086 4 года назад
@@arslan99 does it work the same for real time data? because this API has multiple data already..
@arslan99
@arslan99 4 года назад
@@noura4086 as long as data is in the array of objects it will show 🙂
@noura4086
@noura4086 4 года назад
@@arslan99 Exactly, do you have a video about dealing with realtime data?
@arslan99
@arslan99 4 года назад
@@noura4086 I mean not specifically with real time data. As long as the data is coming into the API you're accessing it will be picked up by the chart but you may need to refresh the page for it to appear. There are ways to make it appear automatically by updating state
@RM_1964
@RM_1964 4 года назад
Hi, I used bar Chart from chart js in my project the only problem I faced is that the bar graph is showing only the first digit of the data I passed. Can you tell me if this kind of error is usual or what.
@arslan99
@arslan99 4 года назад
What could happen is you might've accidentally added a max limiter would you mind showing your code so I can check it out
@irkfaisal
@irkfaisal Год назад
A obj is coming from an API and I want to pass that data by map function through props. Please make a video on it!
@arslan99
@arslan99 Год назад
I think I've already made anther video on it. Please look through my chart js playlist
@irkfaisal
@irkfaisal Год назад
@@arslan99 thanku so much for this😃
@iimCzaR
@iimCzaR 2 года назад
I keep getting "TypeError: Cannot read properties of undefined (reading 'map')" even after copying the code exactly
@arslan99
@arslan99 2 года назад
it seems that react-chartjs had an update if you run into an issue and you follow the exact same steps your chart may run into an issue add this update to it Step 1: import these two packages from chartjs into the Dankmeme component import Chart from "chart.js/auto"; import { CategoryScale } from "chart.js"; Step 2: and be sure to register your chart so add the line below underneath your useeffect component Chart.register(CategoryScale); Hope this helped! :D
@varsha9248
@varsha9248 2 года назад
@@arslan99 Hi, I am getting the same error even after doing the changes. Please help
@arslan99
@arslan99 2 года назад
@@varsha9248 try following my newest chart js video on seeing up charts that should help
@PapoDeGamerBR
@PapoDeGamerBR 4 года назад
Hey man thank you for the video, i have a situation that i really need help to understand how to do it: I'm pretty much creating all the components to bring them to render on app.js and im trying to create the chart but the api I'm working on takes the bitcoin price variation over a range of days (input 1 is the start date and input 2 is the end date), and generates the chart, but how in that click would I be able to get the input values to put in the api url? sorry for my bad english but the resume would be - how can i call the dankmemes funtion on the app.js click to use the input to control de output of the api? thx for the video!
@arslan99
@arslan99 4 года назад
Hey, so it's a bit hard to tell over a comment but I'll try 1. Create two usestate variables one for start date and end date 2. Create a form that will take those inputs and change the use state variables accordingly 3. Then use the usestate variables to change the date available in the chart I think this should work off of the top of my head If your a bit confused how to change date refer to this stack overflow stackoverflow.com/questions/47875045/chart-js-creating-a-line-graph-using-dates
@PapoDeGamerBR
@PapoDeGamerBR 4 года назад
@@arslan99 thx for replying,I've done almost what you said, but I can't bring the this.state.value of each input to a different .js file (all this work I did on the app.js) so how could I use your const dankmemes on my app.js instead?
@arslan99
@arslan99 4 года назад
Okay so I'm understanding a bit better but I feel like there's two different things you talking about. 1. When you say use this.state.value in another .js you would been pass props between the two if you want to do that check out this link it will show how to pass props but it's in class components you're going to have to convert it to state dev.to/zeyadetman/how-to-pass-state-between-components-in-reactjs-2pg1 2. At the bottom your trying to use const dank memes in app.js if that's the case just import the component file dank memes.js into your app.js file I hope this helps 🙂
@chiranjeevichowdary5948
@chiranjeevichowdary5948 3 года назад
You are helping a lot really!!
@vhutshilo2404
@vhutshilo2404 3 года назад
thanks bro ,can you make another video separating axios and chart component
@arslan99
@arslan99 Год назад
what specifically would you like to see ?
@tuantranvan8807
@tuantranvan8807 3 года назад
i got an error TypeError: Cannot read properties of undefined (reading 'map') when reload page
@arslan99
@arslan99 3 года назад
There could be a typo somewhere I'd suggest going through the tutorial again 😃
@tuantranvan8807
@tuantranvan8807 3 года назад
@@arslan99 i fixed it ^^thank ad
@arslan99
@arslan99 3 года назад
@@tuantranvan8807 awesome 😃
@KienNguyen-sg1nf
@KienNguyen-sg1nf 2 года назад
@@tuantranvan8807 Bạn giúp mình lỗi này với được không? Mình bị ik chang
@imadetheuniverse4fun
@imadetheuniverse4fun Год назад
I would hesitate to call this dynamic data. It's data that is being gathered once (during the component mount). I think dynamic data would be something that can change via user interaction or simply change as time passes.
@arslan99
@arslan99 Год назад
True I think the way I meant dynamic was pulling from an API but it does make more sense per user interaction
@fabioribeiro9370
@fabioribeiro9370 4 года назад
Bro, do you know how I could change the dataset and labels dynamically? For example: I have a few buttons that I want to make API calls for currency exchange rates and update the graph, I have buttons for last 7 days and last 30 days, I can't seem to figure out how to make that work, I've tried regular chartjs and react-chartjs. Please help me bro.
@arslan99
@arslan99 4 года назад
Well since the 7 day graph and 30 day graph are different just create both charts that with a ternary operater to render on graph over the other for ex Create a usestate variable call it graphSwitch set it to false and in the functions where you create your graph properties when either graph function is envoked switch between true and false values this is what the ternary operater would look like {graphSwitch ? 7daygraph : 30daygraph} Hope this made sense 🙂
@fabioribeiro9370
@fabioribeiro9370 4 года назад
@@arslan99 It's easy to change datasets using the chart.update() function, but I can't figure out how to do that using React Hooks, how to get the chart instance to update the data, if I were to create a chart for every option (7days, 30days, 6 months, 1 year) that would be a lot of duplicate code.
@arslan99
@arslan99 4 года назад
That's true it would be alot of duplicate code I thought I was for only those two charts. Then not too sure how to approach it. Maybe create one function that will be responsible for one chart at a time but change its values depending on which button clicked you could pass the values between charts from the function parameters :/
@fabioribeiro9370
@fabioribeiro9370 4 года назад
@@arslan99 I did it bro! I put the chart in a variable: [myChart, setChart] = useState({}); then I call a function to set a chart in this variable and use use it for every condition like this myChart.data.datasets[0].data = newData; myChart.data.labels = newLabels; myChart.update(); I did using regular Chartjs instead of react-chartjs, but I will try using it to make the code look cleaner or something.
@arslan99
@arslan99 4 года назад
@@fabioribeiro9370 ayeee good job bro, usually what I do is when I comolete a task in refactor then. Better to get the job done first and make it look pretty then to make it pretty and spend wayyyy to long trying lol but anyways good job!!!
@harshithmurali9857
@harshithmurali9857 3 года назад
Thanks dude this is what I was in need. But how to give the employee_name as the label in the chart? It gives an error as NaN in console. Please get back asap. Thanks in advance!!
@mandarinnu
@mandarinnu 4 года назад
Great tutorial. Thanks!
@arslan99
@arslan99 4 года назад
No problem
@sapucanal
@sapucanal 4 года назад
Thank you for this tutorial!
@arslan99
@arslan99 4 года назад
Glad it was helpful!
@sapucanal
@sapucanal 4 года назад
@@arslan99 I'm thinking about creating a medium post talking about it. If I do this, can I mention your video on it?
@arslan99
@arslan99 4 года назад
Thats awesome I'd love if you metion the video. Once you're done making it tell me the link I'd love to check it out!
@sapucanal
@sapucanal 4 года назад
@@arslan99 medium.com/@sapucaialuann/using-chartjs-and-react-hooks-to-create-a-line-chart-related-to-an-api-acef68f62d46 here's the link of the article I told you about! Thanks again for the inspiration and help with this article.
@crescentmoon5310
@crescentmoon5310 3 года назад
How do we make a chart that we can change with a button?
@arslan99
@arslan99 Год назад
stackoverflow.com/questions/47444222/react-chartjs-change-data-with-a-button
@lahorichoraa4114
@lahorichoraa4114 3 года назад
Brother how to show the strings format in data we have labels and data when i make a project it show numeric data but when it comes towards the string it donot display what i can dooo? like i give you example "• Chart shows users by title (MD, DO, PA NP, Nurse, Pharmacist…) dynamically
@lahorichoraa4114
@lahorichoraa4114 3 года назад
plz help mee!!!!!
@arslan99
@arslan99 Год назад
im sorry for the late reply im not sure im very sorry
@willpickering5829
@willpickering5829 3 года назад
what does the "--save" do in the terminal?
@arslan99
@arslan99 3 года назад
Hey Will, this stack overflow article will answer that for you stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install
@willpickering5829
@willpickering5829 3 года назад
@@arslan99 oh perfect, thanks
@khandoor7228
@khandoor7228 4 года назад
Arslan Thank you man, this is great!
@arslan99
@arslan99 4 года назад
No problemo
@ritheshraj778
@ritheshraj778 4 года назад
Hello Arslan...Very nice video!!! This is what i was looking for...I tried implementing the code but I got a an error saying *TypeError: Object(...) is not a function* ...I tried to fix it..but could not..So could you please suggest me a way out to solve this issue
@arslan99
@arslan99 4 года назад
What point in the video were you? If you can create a pastebin I can check it out
@ritheshraj778
@ritheshraj778 4 года назад
@@arslan99 Thank you very much for the reply. Sure I will do that..but the error is at this point export *const Dankmemes = () => {*
@arslan99
@arslan99 4 года назад
Try removing the export you may be doing it twice
@ritheshraj778
@ritheshraj778 4 года назад
@@arslan99 I removed but the error doesn't seem to resolve
@arslan99
@arslan99 4 года назад
Sry for late reply, I this a problem that I would need to see the entire code to see how to fix. Maybe re follow the tutorial 😕
@prateeksrivastava5628
@prateeksrivastava5628 3 года назад
will you please make a video and show us how to show dynamic data from an API using google charts without react.js?
@arslan99
@arslan99 Год назад
I've never used google charts sorry
@FrostZero
@FrostZero 4 года назад
How can I sort the data for example by salary?
@arslan99
@arslan99 4 года назад
not too sure sry....
@jairoandresvizuetepedraza5492
@jairoandresvizuetepedraza5492 2 года назад
nice
@arslan99
@arslan99 2 года назад
Ty 😎
@veegeecrafts
@veegeecrafts 4 года назад
Why did you use dupple data in your for loop ? I dont understand the Path
@arslan99
@arslan99 4 года назад
What do you mean by duple data
@veegeecrafts
@veegeecrafts 4 года назад
@@arslan99 you wrote data.data in your for loop
@arslan99
@arslan99 4 года назад
@@veegeecrafts well that was cuz the api was structured with data.data so when I requested the data the api was made as api metadata->data->data
@veegeecrafts
@veegeecrafts 4 года назад
@@arslan99 ahh ok thx
@17thsep87
@17thsep87 3 года назад
thank you!
@bhuvaneshpatil8665
@bhuvaneshpatil8665 3 года назад
Hi Arslan , your tutorials are really helping me a lot in my projects.I need small help of yours . I am using state for data property in Line graph it renders first time nicely but when I refresh the page it does not plots anything on chart only blank chart appears.Please do help me with this..!!Thank you so much
@arslan99
@arslan99 3 года назад
Try console logging the state and see what error you get there could be something small that is missing and the console log error should be able to tell you either in the fetch request or where the state is changing
@bronwynpotgieter7405
@bronwynpotgieter7405 2 года назад
what if the data is already variables?
@arslan99
@arslan99 2 года назад
Sorry what do you mean? I'm not sure I understand
@ajayb8730
@ajayb8730 3 года назад
bro how to create a function to console.log the x-axis unit if user clicks on any x-axis unit . please help, Thanks in advance
@arslan99
@arslan99 Год назад
im not too sure sorry
@RiyazBaig-yq9fy
@RiyazBaig-yq9fy Год назад
how to render chart from javascript object can you make video on that?
@arslan99
@arslan99 Год назад
I'm just pure JavaScript?
@RiyazBaig-yq9fy
@RiyazBaig-yq9fy Год назад
@@arslan99 Brother, I send you the data of javaScript object, you try to render the line chart. Once for me
@NevilleBruwer
@NevilleBruwer 4 года назад
Hey bud, that is awesome. New to react. 🤦🏼‍♂️ How do I do Multiple API calls?
@NevilleBruwer
@NevilleBruwer 4 года назад
I see you have a Video with Multiple API calls, watching that now. 💪🏻
@arslan99
@arslan99 4 года назад
@@NevilleBruwer I hope they help ya out!
@samyftaita3832
@samyftaita3832 4 года назад
@@NevilleBruwer me too!! Did you find the solution ?
@arslan99
@arslan99 4 года назад
Lol bit late but If you're looking for that video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Mt3kxUvHORA.html
@ViralMovieShots
@ViralMovieShots 3 года назад
Sir i can't see the return function code in video.. Is there anyway i can get the code??
@arslan99
@arslan99 Год назад
github.com/arslanah99/dynamic-chart-js
@aashishsinghal7331
@aashishsinghal7331 4 года назад
Suggestion / Request - Please make a video on a Multiaxes charts, for example a single chart that has positive y axis for time and positive x axis for temperature and negative x axis for pressure, i am not able to make charts like those please help.
@arslan99
@arslan99 4 года назад
Not too sure on how to do that, because your xaxis would be your labels that you create. You would have to either create labels that correspond to your data manually or create a function that will create them for you.
@shte34567
@shte34567 3 года назад
damnn them thicc bois gonna like this reel much
@arslan99
@arslan99 3 года назад
🥵🥵🥵🥵 🤣
@zaidahmed4254
@zaidahmed4254 3 года назад
can you explain me how to plot charts using weather dataset(csv file) in react js in simple way in short
@arslan99
@arslan99 Год назад
you can covert it to a json and then loop through it into your data obj and use it that way :D
Далее
Борщ в стиле высокой кухни!
00:57
Paint Projects
00:17
Просмотров 4,5 млн
Why Signals Are Better Than React Hooks
16:30
Просмотров 482 тыс.
You might not need useEffect() ...
21:45
Просмотров 166 тыс.
Beautiful Chart Animation with Chart Js Tutorial
23:08
Fetch Data from API in React JS | Learn ReactJS
23:40
How to Fetch Data in React With A Custom useFetch Hook
16:37
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Show Loading Screen While Fetching API Data In React
8:28