詳解plotly.js 繪圖庫入門使用教程
本文介紹了plotly.js 繪圖庫入門使用教程,分享給大家,具體如下:
Plotly
緣起
這兩天想在前端展現數學函數圖像,猜測應該有成熟的 js 庫。
于是,簡單的進行了嘗試。
最后決定使用plotly.js,其他的比如function-plot 看起來也不錯,以后有時間再看。
Plotly
plotly.js is the open source JavaScript graphing library that powers Plotly.
Plotly 可以稱之為迄今最優(yōu)秀的繪圖庫,沒有之一。
簡單案例
代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>plot 繪制圖像</title> </head> <body> <div id="tester" style="width:600px;height:250px;"></div> </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>
效果
點圖
繪制數學圖像
數學圖像繪圖的原理。比如說 y = 2*x+1,實際上就是一系列 (x,y) 的點連接而成的圖像。
代碼
<div id="math-function" style="width:600px;height:250px;"></div> <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>
效果
函數圖像
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
關于laydate.js加載laydate.css路徑錯誤問題解決
日期時間選擇插件 laydate.js相信對大家來說都不陌生,這篇文章主要給大家介紹了關于laydate.js加載laydate.css路徑錯誤問題解決的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-12-12微信小程序:報錯(in promise) MiniProgramError
這篇文章主要介紹了微信小程序:報錯(in promise) MiniProgramError,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10