- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- swiper+echarts實(shí)現多個(gè)儀表盤(pán)左右滾動(dòng)效果
本文實(shí)例為大家分享了swiper+echarts實(shí)現儀表盤(pán)左右滾動(dòng)效果的具體代碼,供大家參考,具體內容如下
a.首先加載插件
<!DOCTYPE html> <html> <head> ... <link rel="stylesheet" href="dist/css/swiper.min.css" > </head> <body> ... <script src="dist/js/swiper.min.js"></script> ... </body> </html>
b.HTML內容
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> </div> <!-- 如果需要分頁(yè)器 <div class="swiper-pagination"></div>--> <!-- 如果需要導航按鈕 --> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> <!-- 如果需要滾動(dòng)條 <div class="swiper-scrollbar"></div>--> </div>
c.你可能想要給Swiper定義一個(gè)大小,當然不要也行。
.swiper-container { width: 600px; height: 300px; }
d.初始化Swiper:最好是挨著(zhù)</body>標簽
<script> var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', // 垂直切換選項 loop: true, // 循環(huán)模式選項 // 如果需要分頁(yè)器 pagination: { el: '.swiper-pagination', }, // 如果需要前進(jìn)后退按鈕 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // 如果需要滾動(dòng)條 scrollbar: { el: '.swiper-scrollbar', }, }) </script>
下面是我要實(shí)現的效果
加載插件和樣式
<!DOCTYPE html> <html> <head> ... <link rel="stylesheet" href="dist/css/swiper.min.css" > <style> *{ margin:0; padding:0; } .swiper-container{ height:200px; width:800px; margin:0 auto; border:1px solid #ccc; } .swiper-slide{ display:flex; } .swiper-slide .chart{ flex:1; } </style> </head> <body> ... <script src="https://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script> <script src="https://cdn.bootcss.com/echarts/4.1.0.rc2/echarts.min.js"></script> <script src="dist/js/swiper.min.js"></script> ... </body> </html>
html結構
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <div class="chart" id="chart1">1</div> <div class="chart" id="chart2">2</div> <div class="chart" id="chart3">3</div> </div> <div class="swiper-slide"> <div class="chart" id="chart4">4</div> <div class="chart" id="chart5">5</div> <div class="chart" id="chart6">6</div> </div> <div class="swiper-slide"> <div class="chart" id="chart7">7</div> <div class="chart" id="chart8">8</div> <div class="chart" id="chart9">9</div> </div> </div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div>
初始化swiper
var mySwiper = new Swiper('.swiper-container', { autoplay: { delay:5000 },//可選選項,自動(dòng)滑動(dòng)\ navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', } })
初始化echarts
function initChart(obj){ var myChart = echarts.init(document.getElementById(obj)); var option = { tooltip : { formatter: "{a} <br/> : {c}%" }, series: [ { type : "gauge", center: ["50%", "50%"], // 默認全局居中 radius : "90%", startAngle: 200, endAngle: -20, axisLine : { show : true, lineStyle : { // 屬性lineStyle控制線(xiàn)條樣式 color : [ //表盤(pán)顏色 [ 0.5, "#DA462C" ],//0-50%處的顏色 [ 0.7, "#FF9618" ],//51%-70%處的顏色 [ 0.9, "#FFED44" ],//70%-90%處的顏色 [ 1,"#20AE51" ]//90%-100%處的顏色 ], width : 20//表盤(pán)寬度 } }, splitLine : { //分割線(xiàn)樣式(及10、20等長(cháng)線(xiàn)樣式) length : 10, lineStyle : { // 屬性lineStyle控制線(xiàn)條樣式 width : 2 } }, axisTick : { //刻度線(xiàn)樣式(及短線(xiàn)樣式) length : 20 }, axisLabel : { //文字樣式(及“10”、“20”等文字樣式) color : "black", distance : 10//文字離表盤(pán)的距離 }, detail: { formatter : "{score|{value}%}", offsetCenter: [0, "40%"], // backgroundColor: '#FFEC45', height:20, rich : { score : { // color : "#333", fontFamily : "微軟雅黑", fontSize :14 } } }, data: [{ value: 56, label: { textStyle: { fontSize: 12 } } }] } ] } setInterval(function () { option.series[0].data[0].value = (Math.random() * 100).toFixed(2) - 0; myChart.setOption(option, true); },2000); }
調用初始化化echats函數
initChart('chart1') initChart('chart2') initChart('chart3') initChart('chart4') initChart('chart5') initChart('chart6') initChart('chart7') initChart('chart8') initChart('chart9')
插播一個(gè)echarts儀表盤(pán)的配置函數
function initChart(obj){ var myChart = echarts.init(document.getElementById(obj)); var option = { tooltip : { formatter: "{a} <br/> : {c}%" }, // toolbox: { // feature: { // restore: {}, // saveAsImage: {} // } // }, series: [ { name: '業(yè)務(wù)指標', type: 'gauge', center: ["50%", "45%"], // 儀表位置 radius: "80%", //儀表大小 detail: {formatter:'{value}%'}, startAngle: 200, //開(kāi)始角度 endAngle: -20, //結束角度 data: [{value: 30, name: '完成率'}], axisLine: { show: false, lineStyle: { // 屬性lineStyle控制線(xiàn)條樣式 color: [ [ 0.5, new echarts.graphic.LinearGradient(0, 0, 1, 0, [{ offset: 1, color: "#E75F25" // 50% 處的顏色 }, { offset: 0.8, color: "#D9452C" // 40% 處的顏色 }], false) ], // 100% 處的顏色 [ 0.7, new echarts.graphic.LinearGradient(0, 0, 1, 0, [{ offset: 1, color: "#FFC539" // 70% 處的顏色 }, { offset: 0.8, color: "#FE951E" // 66% 處的顏色 }, { offset: 0, color: "#E75F25" // 50% 處的顏色 }], false) ], [ 0.9, new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 1, color: "#C7DD6B" // 90% 處的顏色 }, { offset: 0.8, color: "#FEEC49" // 86% 處的顏色 }, { offset: 0, color: "#FFC539" // 70% 處的顏色 }], false) ], [1, new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0.2, color: "#1CAD52" // 92% 處的顏色 }, { offset: 0, color: "#C7DD6B" // 90% 處的顏色 }], false) ] ], width: 10 } }, splitLine: { show: false }, axisTick: { show: false }, axisLabel: { show: false }, pointer : { //指針樣式 length: '45%' }, detail: { show: false } } ] } setInterval(function () { option.series[0].data[0].value = (Math.random() * 100).toFixed(2) - 0; myChart.setOption(option, true); },2000); }
以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站