詳解plotly.js 繪圖庫入門使用教程
本文介紹了plotly.js 繪圖庫入門使用教程,分享給大家,具體如下:
Plotly
緣起
這兩天想在前端展現(xiàn)數(shù)學函數(shù)圖像,猜測應(yīng)該有成熟的 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>
效果

點圖
繪制數(shù)學圖像
數(shù)學圖像繪圖的原理。比如說 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>
效果

函數(shù)圖像
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iis6+javascript Add an Extension File
iis6+javascript Add an Extension File...2007-06-06
獲取HTML DOM節(jié)點元素的方法的總結(jié)
在Web應(yīng)用程序特別是Web2.0程序開發(fā)中,經(jīng)常要獲取頁面中某個元素,然后更新該元素的樣式、內(nèi)容等。如何獲取要更新的元素,是首先要解決的問題。2009-08-08
使用JavaScript解決網(wǎng)頁圖片拉伸問題(推薦)
本文給大家介紹使用javascript解決網(wǎng)頁圖片拉伸問題,本文給大家介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起看看吧2016-11-11

