10

Google Chart Api是否有任何 HtmlHelper 扩展?(我喜欢用于一些基本图表,例如饼图、条形图)

苏萌

4

2 回答 2

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") %>

这应该将其插入您的页面:

替代文字

于 2009-10-08T04:33:23.920 回答
12

谷歌图表 API 的 AC# 包装器。

http://code.google.com/p/googlechartsharp/

使用示例

http://code.google.com/p/googlechartsharp/wiki/UsageExamples

我相信您可以创建一个 HTMLHelper 来合并这个包装类,以使其更容易。

于 2009-10-08T07:34:22.150 回答