highchar的x軸數據自動生成

  • 2019 年 10 月 30 日
  • 筆記

版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。

本文鏈接:https://blog.csdn.net/luo4105/article/details/51831209

highchars的x軸是可以根據數據自動生成的,不過數據類型就和以前不一樣了 官網詳細的例子:http://www.hcharts.cn/test/index.php?from=demo&p=16 其中x軸可以自定義格式

xAxis: {      type: 'datetime',      labels: {          formatter: function() {          	//自定義顯示格式          	return (new Date(this.value)).Format("yyyy-MM-dd");          }      }  },

最後選中的點的顯示

tooltip: {  	enabled: true,  	formatter: function() {  		return '<b>'+ this.series.name +'</b><br/>'+(new Date(this.x)).Format("yyyy-MM-dd") +': '+ this.y +'';  	}  },

這是date加上Format的方法

Date.prototype.Format = function (fmt) { //author: meizz      var o = {          "M+": this.getMonth() + 1, //月份          "d+": this.getDate(), //日          "h+": this.getHours(), //小時          "m+": this.getMinutes(), //分          "s+": this.getSeconds(), //秒          "q+": Math.floor((this.getMonth() + 3) / 3), //季度          "S": this.getMilliseconds() //毫秒      };      if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));      for (var k in o)      if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));      return fmt;  }