Home >Web Front-end >JS Tutorial >plotly.js plotting library introductory tutorial sharing
This article mainly introduces you to the detailed introductory tutorial of plotly.js drawing library. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
Plotly
Origin
In the past two days, I wanted to display mathematical function images on the front end. I guess there should be a mature js library. .
So, I simply tried it.
Finally decided to use plotly.js. Others such as function-plot also look good. I will take a look at it when I have time.
Plotly
plotly.js is the open source JavaScript graphing library that powers Plotly.
Plotly can be called the best graphing library to date ,none of them.
Simple case
Code
##
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>plot 绘制图像</title> </head> <body> <p id="tester" style="width:600px;height:250px;"></p> </body> <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> <!-- test --> <script> TESTER = document.getElementById('tester'); Plotly.plot(TESTER, [{ x: [1, 2, 3, 4, 5], y: [1, 2, 4, 8, 16] }], { margin: {t: 0} }); </script> </html>Effect Point diagram
Drawing mathematical images
The principles of mathematical image drawing. For example, y = 2*x+1 is actually an image formed by connecting a series of (x,y) points.Code
##
<p id="math-function" style="width:600px;height:250px;"></p> <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> <script> TESTER = document.getElementById('math-function'); var x = [], y = []; for(var i = -10; i < 10; i += 1) { x.push(i); y.push(2*i+1); } Plotly.plot(TESTER, [{ x: x, y: y }], { margin: {t: 0} }); </script>
Function image
Related recommendations:
The above is the detailed content of plotly.js plotting library introductory tutorial sharing. For more information, please follow other related articles on the PHP Chinese website!