Click here to Skip to main content
14,829,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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...
Posted
Updated 3-Sep-13 2:08am
v5

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
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900