Hi @RAVI,
You are using the code I provided and I tested it to work. I guess this might be a version issue. What version are you currently using?
I retested a method, you can try it.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var chartData = <%= GetChartDataJson() %>;
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var options = {
title: 'Test',
width: 600,
height: 400,
bar: { groupWidth: "70%" },
legend: { position: "none" },
isStacked: true,
};
var data = google.visualization.arrayToDataTable(chartData);
var chart = new google.visualization.ColumnChart($("#chart")[0]);
chart.draw(data, options);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="chart" style="width: 900px; height: 500px;">
</div>
</div>
</form>
</body>
</html>
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected string GetChartDataJson()
{
List<object> chartData = GetChartData();
return JsonConvert.SerializeObject(chartData);
}
public static List<object> GetChartData()
{
string query = "SELECT * from Table2_Month_Qty";
string constr = ConfigurationManager.ConnectionStrings["CHEMIMSConnectionString"].ConnectionString;
List<object> chartData = new List<object>();
chartData.Add(new object[]
{
"Month", "Quantity"
});
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
chartData.Add(new object[]
{
sdr["Month"], sdr["Quantity"]
});
}
}
con.Close();
return chartData;
}
}
}
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.