這是一個之前在我一個使用 Big5 編碼的網站上遇到的問題
忘記說,這是一個 Classic ASP 的網站
至於為什麼網站還要用 Big5 呢? 不要問,很恐怖
那時候想在某個 Page 上放上一個含有 Facebook 網址的 QR Code
但發現跑出來的圖片怎麼怪怪的,掃也掃不出來
搞了老半天才發現原來是編碼的問題
(其實真正的原因我也不清楚,似乎是 Google 不接受 Big5?)
假設我們的 URL 是
https://www.facebook.com/中文測試123/
使用 api 的網址就是
https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=https://www.facebook.com/中文測試123/
當你把這串文字放到 Page 上,網站就會自動幫你編碼成
https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=https://www.facebook.com/%A4%A4%A4%E5%B4%FA%B8%D5123/
這時候是怎麼掃都沒反應
所以要在把資料 (無論是從DB或寫死) 給 Google 之前轉成 UTF-8
以下是在網路上找到 vbscript 的程式碼,
當初有把網址加到我的最愛,但最近已經失效,最後我還是會把連結給出來
function convertBig5ToUTF8(sourceURL)
dim i,utf8URL,tmp,encodingStr
for i=1 to Len(sourceURL)
tmp = mid(sourceUrl, i, 1)
if asc(tmp) < 0 or asc(tmp) > 128 then '將ascii碼在1~128以外的字元當成中文編成utf8
Session.CodePage = "65001" '先將網頁設成utf8
encodingStr = Server.UrlEncode(tmp) '將中文編成utf8
Session.CodePage = "950" '再將網頁設為Big5
utf8URL = utf8URL & encodingStr
else
utf8URL = utf8URL & tmp
end if
next
convertBig5ToUTF8 = utf8URL
end function
經過轉換後,網址就會變成
https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=https://www.facebook.com/%E4%B8%AD%E6%96%87%E6%B8%AC%E8%A9%A6123/
ref:
asp big5 encoding to utf8 @ Itano Tomomi :: 痞客邦 PIXNET ::
另外找到一篇也是參考上面這一篇的,異曲同工
asp網頁編碼big5->utf8處理辦法
KevinStone's blog
2016年5月25日 星期三
2016年5月23日 星期一
雙Y軸 google chart(double Y-axes google chart)
之前在使用Google Charts繪圖的時候發現一個問題,
在他的範例裡面沒有雙Y軸(或是我沒找到),
也就是Y軸有左邊軸與右邊軸,兩軸的數字不同
後來也忘了是在哪裡找到的
以下是範例(JavaScript)
<!-- Load Google charts api for JavaScript -->
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['corechart']}]}"></script>
<script type="text/javascript">
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['yyy', 'y1', 'y2'],
['2003', 1413000, 111],
['2006', 555000, 118],
['2007', 9400000, 92],
['2008', 3995116, 141],
['2009', 4027797, 147],
['2010', 4266232, 125],
['2011', 4602719, 133],
['2015', 3278581, 119],
['2016', 2043220, 99]
]);
var options = {
title: 'title',
vAxes: { 0: { format: '#,###' }, 1: { format: '#,###' } },
hAxis: { title: 'xtitle' },
series: {
0: { type: "bars", targetAxisIndex: 0, color: "#FFCCFF" },
1: { type: "line", targetAxisIndex: 1, color: "purple" }
}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<!-- Google charts放置的位置-->
<div id="chart_div" style="width: 600px; height: 350px;"></div>
最後應該會看到此圖
ref:Google Charts
2016年5月12日 星期四
有關visual Basic 6(VB6) 四捨五入的方法
簡單來說,VB6的 Integer,Long型態,或CInt,CLng,Round等函數都是四捨六入五逢單才進位
所以要有四捨五入功能就只能用Format
下面這段code跑下去就能了解
Debug.Print "CInt(1.5)=" & CInt(1.5)
Debug.Print "CInt(1.6)=" & CInt(1.6)
Debug.Print "CInt(2.5)=" & CInt(2.5)
Debug.Print "CInt(2.6)=" & CInt(2.6)
Debug.Print "CInt(3.5)=" & CInt(3.5)
Debug.Print "CInt(3.6)=" & CInt(3.6)
Debug.Print "CInt(4.5)=" & CInt(4.5)
Debug.Print "CInt(4.6)=" & CInt(4.6)
Debug.Print "CLng(1.5)=" & CLng(1.5)
Debug.Print "CLng(1.6)=" & CLng(1.6)
Debug.Print "CLng(2.5)=" & CLng(2.5)
Debug.Print "CLng(2.6)=" & CLng(2.6)
Debug.Print "CLng(3.5)=" & CLng(3.5)
Debug.Print "CLng(3.6)=" & CLng(3.6)
Debug.Print "CLng(4.5)=" & CLng(4.5)
Debug.Print "CLng(4.6)=" & CLng(4.6)
Debug.Print "round(1.5)=" & Round(1.5)
Debug.Print "round(1.6)=" & Round(1.6)
Debug.Print "round(2.5)=" & Round(2.5)
Debug.Print "round(2.6)=" & Round(2.6)
Debug.Print "round(3.5)=" & Round(3.5)
Debug.Print "round(3.6)=" & Round(3.6)
Debug.Print "round(4.5)=" & Round(4.5)
Debug.Print "round(4.6)=" & Round(4.6)
Debug.Print "round(1.15,1)=" & Round(1.15, 1)
Debug.Print "round(1.16,1)=" & Round(1.16, 1)
Debug.Print "round(1.25,1)=" & Round(1.25, 1)
Debug.Print "round(1.26,1)=" & Round(1.26, 1)
Debug.Print "round(1.35,1)=" & Round(1.35, 1)
Debug.Print "round(1.36,1)=" & Round(1.36, 1)
Debug.Print "round(1.45,1)=" & Round(1.45, 1)
Debug.Print "round(1.46,1)=" & Round(1.46, 1)
Debug.Print "Format(1.4,0)=" & Format(1.4, "0")
Debug.Print "Format(1.5,0)=" & Format(1.5, "0")
Debug.Print "Format(1.6,0)=" & Format(1.6, "0")
Debug.Print "Format(2.4,0)=" & Format(2.4, "0")
Debug.Print "Format(2.5,0)=" & Format(2.5, "0")
Debug.Print "Format(2.6,0)=" & Format(2.6, "0")
Debug.Print "Format(3.5,0)=" & Format(3.5, "0")
Debug.Print "Format(3.6,0)=" & Format(3.6, "0")
Debug.Print "Format(4.5,0)=" & Format(4.5, "0")
Debug.Print "Format(4.6,0)=" & Format(4.6, "0")
Debug.Print "Format(1.14, 0.0)=" & Format(1.14, "0.0")
Debug.Print "Format(1.15, 0.0)=" & Format(1.15, "0.0")
Debug.Print "Format(1.16, 0.0)=" & Format(1.16, "0.0")
Debug.Print "Format(1.24, 0.0)=" & Format(1.24, "0.0")
Debug.Print "Format(1.25, 0.0)=" & Format(1.25, "0.0")
Debug.Print "Format(1.26, 0.0)=" & Format(1.26, "0.0")
Debug.Print "Format(1.35, 0.0)=" & Format(1.35, "0.0")
Debug.Print "Format(1.36, 0.0)=" & Format(1.36, "0.0")
Debug.Print "Format(1.45, 0.0)=" & Format(1.45, "0.0")
Debug.Print "Format(1.46, 0.0)=" & Format(1.46, "0.0")
關於format要用0還是#都可以,差別在於0在小數位會補0
ref:https://msdn.microsoft.com/en-us/library/wb216dct(v=vs.90).aspx
所以要有四捨五入功能就只能用Format
下面這段code跑下去就能了解
Debug.Print "CInt(1.5)=" & CInt(1.5)
Debug.Print "CInt(1.6)=" & CInt(1.6)
Debug.Print "CInt(2.5)=" & CInt(2.5)
Debug.Print "CInt(2.6)=" & CInt(2.6)
Debug.Print "CInt(3.5)=" & CInt(3.5)
Debug.Print "CInt(3.6)=" & CInt(3.6)
Debug.Print "CInt(4.5)=" & CInt(4.5)
Debug.Print "CInt(4.6)=" & CInt(4.6)
Debug.Print "CLng(1.5)=" & CLng(1.5)
Debug.Print "CLng(1.6)=" & CLng(1.6)
Debug.Print "CLng(2.5)=" & CLng(2.5)
Debug.Print "CLng(2.6)=" & CLng(2.6)
Debug.Print "CLng(3.5)=" & CLng(3.5)
Debug.Print "CLng(3.6)=" & CLng(3.6)
Debug.Print "CLng(4.5)=" & CLng(4.5)
Debug.Print "CLng(4.6)=" & CLng(4.6)
Debug.Print "round(1.5)=" & Round(1.5)
Debug.Print "round(1.6)=" & Round(1.6)
Debug.Print "round(2.5)=" & Round(2.5)
Debug.Print "round(2.6)=" & Round(2.6)
Debug.Print "round(3.5)=" & Round(3.5)
Debug.Print "round(3.6)=" & Round(3.6)
Debug.Print "round(4.5)=" & Round(4.5)
Debug.Print "round(4.6)=" & Round(4.6)
Debug.Print "round(1.15,1)=" & Round(1.15, 1)
Debug.Print "round(1.16,1)=" & Round(1.16, 1)
Debug.Print "round(1.25,1)=" & Round(1.25, 1)
Debug.Print "round(1.26,1)=" & Round(1.26, 1)
Debug.Print "round(1.35,1)=" & Round(1.35, 1)
Debug.Print "round(1.36,1)=" & Round(1.36, 1)
Debug.Print "round(1.45,1)=" & Round(1.45, 1)
Debug.Print "round(1.46,1)=" & Round(1.46, 1)
Debug.Print "Format(1.4,0)=" & Format(1.4, "0")
Debug.Print "Format(1.5,0)=" & Format(1.5, "0")
Debug.Print "Format(1.6,0)=" & Format(1.6, "0")
Debug.Print "Format(2.4,0)=" & Format(2.4, "0")
Debug.Print "Format(2.5,0)=" & Format(2.5, "0")
Debug.Print "Format(2.6,0)=" & Format(2.6, "0")
Debug.Print "Format(3.5,0)=" & Format(3.5, "0")
Debug.Print "Format(3.6,0)=" & Format(3.6, "0")
Debug.Print "Format(4.5,0)=" & Format(4.5, "0")
Debug.Print "Format(4.6,0)=" & Format(4.6, "0")
Debug.Print "Format(1.14, 0.0)=" & Format(1.14, "0.0")
Debug.Print "Format(1.15, 0.0)=" & Format(1.15, "0.0")
Debug.Print "Format(1.16, 0.0)=" & Format(1.16, "0.0")
Debug.Print "Format(1.24, 0.0)=" & Format(1.24, "0.0")
Debug.Print "Format(1.25, 0.0)=" & Format(1.25, "0.0")
Debug.Print "Format(1.26, 0.0)=" & Format(1.26, "0.0")
Debug.Print "Format(1.35, 0.0)=" & Format(1.35, "0.0")
Debug.Print "Format(1.36, 0.0)=" & Format(1.36, "0.0")
Debug.Print "Format(1.45, 0.0)=" & Format(1.45, "0.0")
Debug.Print "Format(1.46, 0.0)=" & Format(1.46, "0.0")
關於format要用0還是#都可以,差別在於0在小數位會補0
ref:https://msdn.microsoft.com/en-us/library/wb216dct(v=vs.90).aspx
訂閱:
文章 (Atom)