且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用脚本在C#中使用Google Charts

更新时间:2023-01-26 12:47:47

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



也许你需要在.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/[^]