js實現(xiàn)圓盤記速表
更新時間:2015年08月03日 11:34:20 投稿:lijiao
本文分享了一個利用AmCharts制作的汽車速度計速表,通過設(shè)置不同的速度(數(shù)字)來動態(tài)改變計速表的指針。使用也非常簡單,下面給出方法。
如何利用AmCharts制作的汽車速度計速表,通過設(shè)置不同的速度(數(shù)字)來動態(tài)改變計速表的指針
效果圖:
javascript代碼:
var chart = AmCharts.makeChart("chartdiv", { "type": "gauge", "theme": "none", "axes": [{ "axisThickness": 1, "axisAlpha": 0.2, "tickAlpha": 0.2, "valueInterval": 20, "bands": [{ "color": "#84b761", "endValue": 90, "startValue": 0 }, { "color": "#fdd400", "endValue": 130, "startValue": 90 }, { "color": "#cc4748", "endValue": 220, "innerRadius": "95%", "startValue": 130 }], "bottomText": "0 km/h", "bottomTextYOffset": -20, "endValue": 320 }], "arrows": [{}] }); window.onload=function(){ chart.arrows[0].setValue(80); chart.axes[0].setBottomText(80 " km/h"); } document.getElementById("btnSure").onclick=function(){ if(document.getElementById("txtNum").value>320){ alert("超出最大值"); return; } if(document.getElementById("txtNum").value<0){ alert("不能低于0"); return; } chart.arrows[0].setValue(document.getElementById("txtNum").value); chart.axes[0].setBottomText(document.getElementById("txtNum").value " km/h"); }
引入JS:
<script type="text/javascript" src="amcharts.js"></script> <script type="text/javascript" src="gauge.js"></script> <script type="text/javascript" src="none.js"></script>
以上就是本文的全部內(nèi)容,希望大家喜歡。
您可能感興趣的文章:
相關(guān)文章
JavaScript解構(gòu)賦值的5個常見場景與實例教程
解構(gòu)賦值是一種特殊的語法,它使我們可以將數(shù)組或?qū)ο蟆安鸢睘榈揭幌盗凶兞恐?因為有時候使用變量更加方便,下面這篇文章主要給大家介紹了關(guān)于JavaScript解構(gòu)賦值的5個常見場景與實例的相關(guān)資料,需要的朋友可以參考下2021-11-11Javascript中apply、call、bind的巧妙使用
Javascript中apply、call、bind都是為了改變函數(shù)體內(nèi)部 this 的指向。下面通過本文重點給大家介紹js中apply,call,bind的巧妙使用方法,感興趣的朋友一起學(xué)習(xí)吧2016-08-08