日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(转)数字格式化函数:Highcharts.numberFormat()

發布時間:2025/3/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (转)数字格式化函数:Highcharts.numberFormat() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、函數說明

該函數用于圖表中數值的格式化,常見用途有數值精度控制、小數點符、千位符顯示控制等。 二、函數使用 1、函數構造及參數 Highcharts.numberFormat?(Number number, [Number decimals], [String decimalPoint], [String thousandsSep]) 參數列表
  • number ? 需要格式化的數字
  • decimals? 小數保留位數,最后一位是四舍五入,默認為 0(可選參數)
  • decimalPoint ? 小數點符,默認是“.”(可選參數)
  • thousandsSep 千位符,默認是“,” (可選參數)
返回值類型:String 詳見API 文檔 :?http://www.hcharts.cn/api/index.php#Highcharts.numberFormat 2、舉個栗子 對于數字 12223.8723 Highcharts.numberFormat(12223.87) ? =?12,224? ? ? (默認精度是0) Highcharts.numberFormat(12223.87, 2) ? =?12223.87 ? (保留兩位小數) Highcharts.numberFormat(12223.87, 2, ",", " ") ? =?12 223,87 ? (小數點用“,”,千分符用“ ”) Highcharts.numberFormat(12223.87, 2, ".", "") ?? =?12223.87 ?? (不顯示千分符) 三、操作實例 餅圖的數據及dataLabels 的格式化函數如下 plotOptions: { pie: { ? ??dataLabels: { ? ? ? ??enabled: true, formatter: function() {? ? ??return ?this.point.name?+ this.percentage + '%'; } ? ??} } },? ?? series: [{? type: 'pie',? name: 'Browser share',? data: [? ? ??['Firefox', 45.60],? ? ??['IE', 26.68], ? ??{? name: 'Chrome', y: 12.68,? sliced: true,? selected: true? ? ??}, ? ??['Safari', 8.65],? ? ??['Opera', 6.62],? ? ??['Others', 0.67] ] }] 這時候我們看到的餅圖文字標簽(dataLabels)為 圖中的數字(dataLabels中的餅圖扇區所占百分比)就會顯示出沒有經過精度控制的內容,利用Highcharts.numberFormat() 我們就可以控制該數值的精度。 formatter: function() {? return this.point.name?+ Highcharts.numberFormat(this.percentage,2) + '%'; } 至此已基本說清楚 Highcharts.numberFormat() 函數的作用了,下面說下關于該函數更多用處及數字格式化相關內容。 四、相關內容 1、需要用到數值格式化函數的地方 在圖表中有很多地方也有可能需要用到數值格式化函數,歸納如下
  • 坐標軸文字(Axis.labels):對應的格式化函數是?xAxis.labels.formatter、yAxis.labels.formatter
  • 數據提示框(tooltip):對應的格式化函數是?tooltip.formatter
  • 數據點文字(dataLabels):plotOptions.series.dataLabels.formatter?及 ?plotOptions.{chartType}.dataLabels.formatter
2、用于數值格式化的其他方法 同樣是格式化,Highcharts還提供了更簡便的方法,也就是 format 字符串 ,例如與?plotOptions.series.dataLabels.formatter?對應的就是?plotOptions.pie.dataLabels.format 示例代碼 plotOptions: { pie: { dataLabels: { ? ??enabled: true, formatter: function() {? return ?this.point.name?+ this.percentage + '%'; }, // 對應的format format:"{point.name} + {percentage}"; } } },? ?? 也就是 formatter 是函數,format 是格式字符串,關于兩者的區別及優點這里就不多說,我們來說說format是如何進行數值精度控制的。 formatter: function() {? return this.point.name?+ Highcharts.numberFormat(this.percentage,2) + '%'; } format:"{point.name} {this.percentage:.2f}" {this.percentage:.2f}?即 {數值:.精度f} 轉自:http://bbs.hcharts.cn/article-54-1.html

轉載于:https://www.cnblogs.com/Dyyuan/p/4948394.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的(转)数字格式化函数:Highcharts.numberFormat()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。