How to Connect a CSV File with Fetch in Chart JS
ฝัง
- เผยแพร่เมื่อ 6 ก.พ. 2025
- How to Connect a CSV File with Fetch in Chart JS
In this video we will explore how to connect a CSV file with the fetch API in Chart.js. Many charts are written based on a CSV file. Quite often you can use different libraries such as Papa Parse.js or the D3.js to use their build in options. Luckily it is not really needed once you understand how to do it directly in Javascript.
We will be extract the data form the CSV file using fetch and clean the arrays, modify where needed and show them on the chart at once. The result is absolutely great.
Let's explore this right now!
▬ Chartjs Viewers Question Series ▬▬▬▬▬▬▬▬▬▬
This is part of the Chartjs Viewers Question series. Where we answer viewer questions. This question was asked by one of our viewers.
▬ Materials/References ▬▬▬▬▬▬▬▬▬▬
To keep the video short we might expect you to know parts. These parts we have explained in other videos. You can find the references here below:
Understand setup, config and render init blocks: • How to use config and ...
Starting Code: www.chartjs3.c...
▬ Got a Question? Comment! ▬▬▬▬▬▬▬▬▬▬
Got a question or special request about a specific item? Comment below and tell me your question. I will make sure to follow up on you!
▬ Find Me Here ▬▬▬▬▬▬▬▬▬▬
Blog: www.chartjs3.c...
Website: www.chartjs3.com
Udemy Course: www.udemy.com/...
Chart JS tutorials for Beginners:
🎓 Beginners Serie: • ChartJS intro creating...
Chart JS tutorials for Intermediate:
👁️ Most Watched Chart JS Video: • Update dynamic chart j...
⭐ Personal Favorite Chart JS Video: • How to make an interac...
Chart JS Dashboard Series:
👍 Most Liked Video Series:
Watch Part 1: • How to make a chart dy...
Watch Part 2: • How to make a chart dy...
Watch Part 3: • How to add a dynamic c...
▬ About Us ▬▬▬▬▬▬▬▬▬▬▬▬
Why we created these #chartjs and #javascript video tutorials?
WHY
Creating charts in javascript is very rewarding but extremely challenging. The Chart JS library made it easier to render charts. However the chart js documentation is hard to understand for many. It requires a lot of different moving parts to work along. The canvas tag, javascript, arrays and Chart JS all need to be combined to draw an eye catching bar chart or line chart.
The videos explains the chart js documentation in a more visual and easy to understand way. You can follow along with the code and quickly grasp how it works. We cover the code in chart js but also what truly happens and why something happens when we write a line of code. This fundamental understanding gives clarity to you as a developer in chartjs. In short it is the Chart JS video documentation.
HOW
We answer questions from YOU (viewers) by creating an answer video that covers the questions YOU have posted in the comment section.
WHAT
Our goal is to help YOU learn how to draw charts in Chart JS by showing you in video format how to do it.
Chart JS Video Documentation Site: www.chartjs3.com
▬ Chart JS 3.5.1 ▬▬▬▬▬▬▬▬▬▬▬▬
Chart JS is a javascript library to draw charts in the canvas tag on your site. Presenting data in a visual manner such as charts is more effective and appealing. All the charts are always coded in the latest Chartjs version which is as of this recording Chart JS 3.5.1.
What type of charts can you make with Chart.JS?
With chart js you can make line chart, bar chart, pie chart, doughnut chart, scatter chart, polar area chart, radar chart, gauge chart and area chart. And with some clever tricks and visual adjustment more can be done.
Thanks! Very helpful. I have been creating charts for years (at my job) using Excel VBA and large CSV files. Recently, I started writing code to convert CSV to JSON for ChartJS. After watching this video... I don't need to mess with JSON. Fetch CSV's instead!
Thank you for the tutorial
How can I increase the pointer at a specific point, with your example that is to say
In 2006 on the red line at 200, only the pointer is bigger,
I hope I have explained myself well in my question.
Sir could you add some more videos using buttons and csv files ..
Hi Arnab, thank you for your question. I created an answer video covering your question here: th-cam.com/video/rFqW6A57UvA/w-d-xo.html
This will show you a way to do it which is considered a "trick". This is to avoid having multiple function where you have to move the data from one function to another. I will cover more items related to CSV files soon.
Thank you, this was a good one!
I tried to use own data with 104 rows and 3 columns, of some (for me) weird reason some of the data didn't display. Randomly one or another "point", though there was data in the *.csv. Any hints?
Hi Anne, thank you for your kind words. If everything works except a few random values if might mean that the value is not recognized as a correct type.
Try to check that specific point in your CSV file and check if it might have extra white space, or anything else that could differ from the others. Or copy the file save in Excel as CSV and empty that specific cell and retype it.
If everything is correct and it still does not works an alternative option would be to crosscheck the your CSV with an alternative method. This video: th-cam.com/video/HFAjrai-d58/w-d-xo.html
This video shows you how to draw a chart with Papa Parse JS. This a JS library for reading CSV files.
Instead of using
, how can I split the tabledata? Because some of my cells contains alt enter and the code puts them in new line so my whole datastructure is shifted
how we run csv file in localhost?
could you please provide video
This is a very helpful video. But could you also show to have the csv file to a localhost?
Hi React Dev TV, thank you for your question. Depending on your OS. If you use Windows I use you can use MAMP for Apple OS you can use XAMP. Which tend to be the more old fashion way that I am more familiar with.
But it is also possible to use a virtual machine/terminal where you can run REACT, VUE or ANGULAR. My skills in this topic is still not fully developed to explain it in details. If you run REACT in a terminal you could just run JS in the terminal and have the site running. However, once I know this more in depth I will cover this.
@@ChartJS-tutorials Thanks a lot for your response. Can you demonstrate also how you used MAMP for this project? Would really appreciate it alot..
Hi sir, I have a "Google sheets", but it brings me even the HTML code. And I tried to research on the Internet. But the Google API changes and I have many troubles when I use it on my chart...
Do you have a video or a blog talking to this?? Thanks
How and from where to get the localhost URL please explain from scratch