我在我的网站中使用谷歌图表,当我在VS中调试应用程序时一切正常但是当我发布应用程序时,图表是空白的! 在这方面你能帮助我吗
这是我的代码:
<script src="Scripts/jquery-1.9.1.js"></script>
<link href="Content/Site.css" rel="stylesheet" />
<script type="text/javascript" src="Scripts/googlechart.js"></script>
<%--<script type="text/javascript" src="Scripts/googlechart2.js"></script>--%>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>
var chartData; // globar variable for hold chart data
google.load("visualization", "1", { packages: ["corechart"] });
// Here We will fill chartData
$(document).ready(function () {
$.ajax({
url: "Main.aspx/GetChartData",
data: "",
dataType: "json",
type: "POST",
contentType: "application/json; chartset=utf-8",
success: function (data) {
chartData = data.d;
},
error: function () {
alert("Error loading data! Please try again.");
}
}).done(function () {
// after complete loading data
google.setOnLoadCallback(drawChart);
drawChart();
});
});
function drawChart() {
var data = google.visualization.arrayToDataTable(chartData);
var options = {
title: "Vehicle",
pointSize: 5
};
var lineChart = new google.visualization.LineChart(document.getElementById('chart_div'));
lineChart.draw(data, options);
}
</script>
返回代码
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object[] GetChartData()
{
List<PL_PK> data = new List<PL_PK>();
//Here MyDatabaseEntities is our dbContext
using (PLCPEntities dc = new PLCPEntities())
{
data = dc.PL_PK.ToList();
}
var chartData = new object[data.Count + 1];
chartData[0] = new object[]{
"Time",
"Total",
"Plan",
};
int j = 0;
foreach (var i in data)
{
j++;
chartData[j] = new object[] { i.Time.ToString("MMM" + "dd"), i.Total, i.Plan };
}
return chartData;
}