hello friends ..
i am trying to do google line chart..
i have done with coding ..But it is not displaying ..can u identify the error.
source code :
StringBuilder str = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
chart_bind();
}
}
private DataTable GetData()
{
CRMBLL objBAL = new CRMBLL();
CommonFunctions comObj = new CommonFunctions();
DataSet ds = comObj.ExecuteDataset("select * from dbo.repo");
var test = ds;
DataTable dt = new DataTable();
dt = ds.Tables[0];
return dt;
}
private void chart_bind()
{
DataTable dt = new DataTable();
try
{
dt = GetData();
str.Append(@"<script type=text/javascript> google.load( visualization, 1, {packages:[*corechart*]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'year');
data.addColumn('number', 'contacted');
data.addColumn('number', 'qualified');
data.addColumn('number', 'demodone');
data.addRows(" + dt.Rows.Count + ");");
Int32 i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
str.Append("data.setValue( " + i + "," + 0 + "," + "'" + dt.Rows[i]["year"].ToString() + "');");
str.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["contacted"].ToString() + ") ;");
str.Append("data.setValue(" + i + "," + 2 + "," + dt.Rows[i]["qualified"].ToString() + ") ;");
str.Append("data.setValue(" + i + "," + 3 + "," + dt.Rows[i]["demodone"].ToString() + ");");
}
str.Append(" var chart = new google.visualization.LineChart(document.getElementById('chart_div'));");
str.Append(" chart.draw(data, {width: 599, height: 400,color: 'Green',");
str.Append("hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},");
str.Append(@"series: {0:{color:'#676767',lineWidth:2,pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
1:{color:'#00b0f0',lineWidth:2,pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
2:{color:'green',lineWidth:2, pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
}");
str.Append("}); }");
str.Append("</script>");
lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
}
catch
{ }
}
html code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GIG</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="lt" runat="server"></asp:Literal>
</div>
<div id="chart_div"></div>
</form>
</body>
</html>