一、項目需求提示框中需要顯示當前時間(常規的提示并不能達到這種效果)
樣式
二、知識點
highCharts圖表tooltip屬性中有一個formatter屬性
formatter: function() {……}
提示框內容格式化回調函數,返回 false 可以針對某個點或數據列關閉提示框,該函數里可以執行復雜的邏輯來返回需要的內容。
三、代碼
shared: true,//當提示框被共享時,整個繪圖區都將捕捉鼠標指針的移動。提示框文本顯示有序數據(不包括餅圖,散點圖和標志圖等)的系列類型將被顯示在同一個提示框中。 formatter : function() {//提示框內容格式化回調函數,返回 false 可以針對某個點或數據列關閉提示框,該函數里可以執行復雜的邏輯來返回需要的內容。 var content = ''; for (var i = 0; i < this.points.length; i++) { if(i == this.points.length-1){ content += '<span style="font-size: 10px; color: ' + this.points[i].series.color + '">' + this.points[i].series.name + '</span>: ' + this.points[i].y +'℃'+'<br/>'; }else{ content += '<span style="font-size: 10px; color: ' + this.points[i].series.color + '">' + this.points[i].series.name + '</span>: ' + this.points[i].y +'%'+'<br/>'; } }; var date = new Date(); var nowYear=date.getFullYear().toString(); var nowMonth=(date.getMonth() + 1).toString(); var nowDay=date.getDate().toString(); var nowHours=date.getHours().toString(); var nowMin=date.getMinutes().toString(); var nowSeconds=date.getSeconds().toString(); function timeAdd0(str) { if(str.length<=1){ str='0'+str; } return str } nowYear=timeAdd0(nowYear) ; nowMonth=timeAdd0(nowMonth) ; nowDay=timeAdd0(nowDay) ; nowHours=timeAdd0(nowHours) ; nowMin=timeAdd0(nowMin); nowSeconds=timeAdd0(nowSeconds) content = '<span>' + nowYear + '/' + nowMonth + '/' + nowDay + ' ' + nowHours + ':' + nowMin + ':' + nowSeconds + ' year' + '</span><br/>' +content; return content; },
四、效果
若有不足請多多指教!希望給您帶來幫助!
總結
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com