能否利用MapGuide 製作專題圖進行商務分析一直是眾多開發人員關注的焦點之一。現在MapGuide自身的功能已經支援按地區建立色塊分析專題圖了,比如分析中國地圖以省為單位的人口密度情況,人口密度大的省份用深紅色表示,人口稀少的省份用明黃色表示,這樣就可以建立出人口分布專題圖,這個功能無論是在Map 3D還是在MapGuide OpenSource或Enterprise版中都是很簡單的,MapGuide的例子程式Theme即可完成。那麼MapGuide能否支援基於地塊的餅狀圖或者柱狀圖呢?比如要按照省份統計每個省的人口年齡層次狀況,那我需要在點每個省時,用餅狀圖或者柱狀圖表示未成年人、中青年人和老年人各佔多少比例,現在MapGuide還不能直接在地圖上產生這樣的專題圖。但現在也不是沒有辦法。
也許有人還記得我許久以前的一篇文章給MapGuide Open Source的ToolTip加點料, 這篇文章講述了如果在MapGuide ToolTip中加入圖片,後來無意中看到了Google的Chart API,覺得在這上面肯定可以做些文章。後來一忙就忘了。不過所幸,後來Jackie Ng做了這個工作了,貼出來給大家共用一下。原文在http://themapguyde.blogspot.com/2009/07/expressive-power-of-mapguide-tooltips.html,國內使用者可能訪問不了。我轉一下過來。
Google offers a free API that lets you generate dynamic charts and graphs all from a simple url. This graph below is one such example (right click and view the page source if you want)
This chart is basically a HTML img tag with the following url:
http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=HelloWorld
If you study the url carefully, you'll see that there is a parameter asking for the values to be charted, and another parameter asking for the labels for these charted values. Now consider the Parcels layer of the Sheboygan sample dataset:
Suppose we want to represent the values of RYEAR, GEOEXTRA and RBLDGVC in a pie chart (I know this probably makes no sense from a reporting perspective, it's just for the sake of argument)
The tooltip expression for the Parcels layer would be something like:
我簡單做了一下,你可以貼過去試試。
Concat ( Concat ( Concat ( Concat ( Concat ( Concat ( Concat ( '<img src = http://chart.apis.google.com/chart?chs=250x100&chd=t:', RYEAR ), ',' ), GEOEXTRA ), ',' ), RBLDGVC ), '&cht=p3&chl= ' ), ' RYEAR|GEOEXTRA |RBLDGV />' )
When we now put our mouse over a Parcel, this is what we get:
Pretty cool eh?
怎麼樣,效果還算可以吧,雖然需要滑鼠指上去才顯示,但總比沒有強些
這隻是個引子,注意到ToolTip中只是個HTML,其實只要你有想象力,可以放任何html代碼進去,呵呵。 有時間試試看吧。