Click here to Skip to main content
15,896,382 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
code in .cs file

        // complete code of Visualization: Combo Chart
        SqlConnection con = new SqlConnection();
        // here am declairing the stringbuilder class
        StringBuilder str = new StringBuilder();
        SqlCommand cmd;
// here datatale dt is fill wit the adp
             adp.Fill(dt);
             // this string m catching in the stringbuilder class
             // in the str m writing same javascript code that is given by the google.

             str.Append(@"<script type=text/javascript>  google.load('visualization', '1', {'packages':['corechart']});
                  google.setOnLoadCallback(drawChart);
                  function drawChart() {
                  var data = new google.visualization.DataTable();");
             // but m changing  only below line
             // (" data.addColumn('string'(datatype), 'student_name'(column name));");
             // str.Append(" data.addColumn('number'(datatype), 'average_marks'(column name));");
             // my data that will come from the sql server
             str.Append(" data.addColumn('string', 'reward');");
             str.Append(" data.addColumn('number', 'SrNo');");
             str.Append(" data.addRows([");
             // here i am declairing the variable i in int32 for the looping statement
             Int32 i;
             // loop start from 0 and its end depend on the value inside dt.Rows.Count - 1
             for (i = 0; i <= dt.Rows.Count - 1; i++)
             {
                 // here i am fill the string builder with the value from the database
                 str.Append("['" + (dt.Rows[i]["reward"].ToString()) + "'," + dt.Rows[i]["SrNo"].ToString() + "],");
             }
             // other all string is fill according to the javascript code
             str.Append(" ]);");
             str.Append(" var chart = new google.visualization.PieChart(document.getElementById('chart_div'));");
             //  str.Append(" var chart = new google.visualization.BarChart(document.getElementById('chart_div'));");
             str.Append("chart.draw(data, {width: 1200, height: 500,title: 'Students Record'});}");
             str.Append("</script>");
             // here am using literal conrol to display the complete graph
             lt.Text = str.ToString().TrimEnd(',');
             con.Close();


code in .aspx

    <div>
        <asp:Literal ID="lt" runat="server"></asp:Literal>
    </div>
    <div id="chart_div">
    </div>
Posted
Updated 1-Aug-13 18:03pm
v4

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