2009-10-08 42 views

回答

17

谷歌說,你插入像這樣的圖表:

<img src="http://chart.apis.google.com/chart? 
    chs=250x100 
    &amp;chd=t:60,40 
    &amp;cht=p3 
    &amp;chl=Hello|World" 
    alt="Sample chart" 
/> 

因此,它應該是很容易寫這樣的的HtmlHelper(未經測試):

namespace System.Web.Mvc.Html 
{ 
    public static class GoogleChartHelpers 
    { 
     public static string GoogleChart 
      (string cht, string chd, string chs, string chl) 
     { 
      return "<img source='http://chart.apis.google.com/chart?cht=" + cht 
       + "&amp;chd=" + chd 
       + "&amp;chs=" + chs 
       + "&amp;chl=" + chl + "' />; 
     } 
    } 
} 

,並調用它像這樣:

<%= Html.GoogleChart("P3","t:60,40","250x100","Hello|World") %> 

應該插入到你的頁面這樣的:

alt text