hello and welcome to red stapler channel
in this tutorial I am going to show you how to create a real timeline chart with
JavaScript using Plotly.js a charting library that was built on top of d3.js
and stack.gl very useful for displaying various chart types with great
performance and also support 3d charts using WebGL ready let’s check it out first if you are not using NPM let’s
start with downloading the latest version from github and include it to
your page using script tag and next create a development for the
chart now we will need to retrieve the data
point to screen the chart this can be in form of AJAX call to the API endpoint or
it can be the result from the calculation on your own website anyway
for the simplicity we will use random value for this tutorial
and next we will create a line chart using Plotly.plot plot function and pass
the element ID as first parameter followed by the chart definition object
first is the y-axis data array so I’m going to pass an array and call get data
function to retrieve the first data point for our chart and next we will set
the chart type to line as we want to create a line chart
if you run the code now you will have a chart with our first data point and next we will add a code to
automatically retrieve the next data point and update the chart
I’m going to use setinterval for every 200 milliseconds this will be your chart
updating frequency and you can change the interval time as you like now inside
we will call Plotly.extendTraces this is the basic function to extend the
current chart with a new set of data points. we’ll pass the chart element ID
followed by the data object you will notice that I used 2D array because
Plotly support multiple traces in a single chart so you can provide multiple
data arrays for each trace with a single call of this function and the last one is
the array of index of chart traces that you want to extend with the data
provided since we only have one trace we will use 0 so let’s see how it works now if you want the chart to slide along
with the new data like this we can use relayout function to update the x-axis
range first create a counter and increment it for each time the new data
point is appended let’s say if you want to display 500
data points before we begin to slide the chart we will pass our chart element ID as usual and next we will redefine the x-axis
range we will set the starting value to the current count minus by 500
and use the current count as ending range and that’s it let’s see the result so that’s all for this tutorial please
find the link to the code at the video description box below please feel free
to like or subscribe if you want to stay updated with us for more video like this
thanks for watching and see you in the next video bye
34 Comments
first wow
Most useful channel i have found period
can you make tutorial for create real-time chart using highcharts JS ?? please
Can you make one for Chart.Js using SQL data?
I have downloaded plotly.min.js and put it in the same folder as my html file and still cannot get anything to show when I run the source code besides the title "Real-Time Chart with Plotly.js
English ki acting kyu kar rha hai.
Hi, how to open this index.html on localhost server?
I always error "Failed to load resource: the server responded with a status of 404 (Not Found)"
Thanks a lot for it! Very helpful! Did you make a real time graph with a .csv file?
awesome
Is there a way to save data to MySql..??
Can you create more than one line?
Amazing video. Thank you. Do you know how I would go about labeling the x-axis to show time since? For example the x-axis would -5 minutes ago, -10 minutes ago and -15 minutes ago? Thank you
BEST TUTORIAL FOR THIS THANK YOU
Hey I copied the source code into my own application just to see if anything would display. I can only get the "Real-Time Chart with Plotly.js" to display on page. Do i need to provide css stylings for the chart? Has anyone else experienced this issue?
can this method (setinterval and extendtraces) be used to animate 3d scatter plot?
Hi. Thanks for this tutorial. Has helped me a lot. I was wondering what changes to make to this if I want the graph to scroll to show the new lines being plotted as the data is added to the graph?
You saved my fxcking ass buddy!
Thank you man!
what is npm?
is plotly.js free? I wanted to use to display in my android application
Thank you!! This tutorial helps me a lot . I have a question, how can I add y-axis's name and x-axis's name?
You really help me with this tutorial. thank you very much
how to make it without libraries?
Is it possible to create real time charts without using intervals?
what software did you use to write coding in this video?
Thank you so much! This video was extremely helpful haha 🙂
Useful tutorial. I just made a subscriber gap graph for YouTube. Literally no other person would explained like that.
Thank you. this tutorial help me.
I have one question. I have a problem making charts in real time. I will display a chart where the data source is from the database. please help the solution of my problem. please be able to share the javascript code
What should i write in getData() to plot real-time data from google firebase? please help me out
Sweet and short to the point…Subscriber for life
How to show data from database
Where is Database?
Nowadays, you can remove the `cnt` counter, and include a third parameter in extendTraces, the length of total data: .extendTraces('graph',{…},500), and remove the .relayout(…) line. Faster.