使用脚本在C#中使用Google Charts [英] Google Charts in C# using Script

查看:68
本文介绍了使用脚本在C#中使用Google Charts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   void 显示(DataView数据视图)
{
string values = ;
string url = https:// www.google.com/jsapi;
System.Text.StringBuilder javaScript = new System.Text.StringBuilder();
javaScript.Append( < script type = \text / javascript \src = + url + >< / script>);
javaScript.Append( < script type = \text / javascript \> google .load(\visualization \,\1 \,{packages:[\corechart \]}););
javaScript.Append( google.setOnLoadCallback(drawChart); function drawChart(){var data = google。 visualization.arrayToDataTable([['Date','WMins'],);

for int loopCount = 0 ; loopCount < dataview.Count; loopCount ++)
{
values = values + [' + dataview [ loopCount] [ 3 ]。ToString()+ ' , + Math.Round( float .Parse(dataview [loopCount] [ 9 ] .ToString()))+ ],;
} // 其中i初始化我的谷歌图表数据...
values = values.Substring( 0 ,values.Length - 1 );
javaScript.Append(values);
javaScript.Append( ]););
javaScript.Append( var options = {title:'Productivity Performance',hAxis:{title:' Date',titleTextStyle:{color:'red'}}}; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data,options);} );
javaScript.Append( < / script>);

Page.RegisterStartupScript( Graph,javaScript.ToString()) ;

}









我可以得到谷歌图表。但是当我在aspx designer(MainContent)页面中使用此代码作为普通的java脚本时,我得到此图表...帮我获取此图表...

解决方案

不确定问题,但可能是加载元素......



也许你需要在.document.ready event [ ^ ]。

Page.RegisterStartupScript是果然可以在HTML的末尾运行,但也许还有一些JS尚未加载?



尝试将事件附加到安全的一边。



Best,H


查看链接..



google-charts-in-asp-net-web-application / [ ^ ]



这是API



http ://googlecharts.codeplex.com/ [ ^ ]

public void Display(DataView dataview)
    {
        string values = "";
        string url="https://www.google.com/jsapi";
        System.Text.StringBuilder javaScript = new System.Text.StringBuilder();
        javaScript.Append("<script type=\"text/javascript\" src="+url+"></script>");
        javaScript.Append("<script type=\"text/javascript\"> google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});");
        javaScript.Append("google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Date', 'WMins'],");

        for (int loopCount = 0; loopCount < dataview.Count; loopCount++)
        {
            values = values + "['" + dataview[loopCount][3].ToString() + "'," + Math.Round(float.Parse(dataview[loopCount][9].ToString())) + "],";
        }//where i initialize my data for google chart...
        values = values.Substring(0, values.Length - 1);
        javaScript.Append(values);
        javaScript.Append("]);");
        javaScript.Append("var options = {title: 'Productivity Performance',hAxis: { title: 'Date', titleTextStyle: { color: 'red'} }}; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options);}");
        javaScript.Append("</script>");

        Page.RegisterStartupScript("Graph", javaScript.ToString());     
        
    }





I can't Get Google Chart .But i get this chart when i used this code in aspx designer(MainContent) page as a normal java script...Help me to get this chart...

解决方案

Not sure about the problem but it could be loading elements ...

Perhaps you need to run your JS on the document.ready event[^].
The Page.RegisterStartupScript is sure enough to run at the end of the HTML but perhaps some JS is not yet loaded?

Try attaching to the event to be on the safe side.

Best, H


Check the link..

google-charts-in-asp-net-web-application/[^]

Here is the API

http://googlecharts.codeplex.com/[^]


这篇关于使用脚本在C#中使用Google Charts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆