function Piee() {
$('#Pie').parent().find('.loding_box_outer').show().fadeIn();
var startdate = '2017/1/10';
var val1, val2, val3, val4, val5, val6 = null;
var emp = 20;
myData = "{ 'date':'" + startdate + "', 'Level1':'" + val1 + "','Level2':' " + val2 + "','Level3':'" + val3 + "','Level4':'" + val4 + "','Level5':'" + val5 + "','Level6':'" + val6 + "', 'EmployeeId':'" + emp + "'}";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../NewDashboard.asmx/PIECHART",
data: myData,
async:false,
cache: false,
dataType: "json",
success: drawChart,
// function (data) {
// var json = $.parseJSON(data.d);
// var jsondata = [];
// $.each(json, function(i, serial){
// for(var i in serial)
// {
// var array_need = new Array(i, parseFloat(serial[i]));
// jsondata.push(array_need);
// }
// });
// drawChart(jsondata);
//},
error: function (data) {
alert("Error Found");
}
});
}
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawChart);
function drawChart(data)
{
//alert(data);
var json = $.parseJSON(data.d);
//var list = json;
//alert(json);
// var jsondata = ['One', 'two', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];
var jsondata = ['One', 'two','three','four','five','six','seven'];
// alert(jsondata);
//$.each(json, function (i, serial) {
// alert(serial);
//for (var i in jsondata) {
//alert(jsondata)
//var array_need = new Array(i, parseFloat(jsondata[i]));
//alert(array_need)
//jsondata.push(array_need);
//alert(jsondata)
//}
//$.each(json, function(i, serial)
//{
for(var i in jsondata)
{
var serie = [];
//jsondata.push(json[i].One);
//jsondata.push(json[i].two);
//jsondata.push(json[i].three);
//jsondata.push(json[i].four);
//jsondata.push(json[i].five);
//jsondata.push(json[i].six);
//jsondata.push(json[i].seven);
series.push(jsondata[i].One);
serie.push(parseFloat(jsondata));
alert(serie);
//jsondata.push(json[i].One)
//jsondata.push(json[i].One)
//jsondata.push(json[i].One)
//jsondata.push(json[i].One)
//jsondata.push(json[i].One)
//jsondata.push(json[i].One)
// alert(json);
// var array_need = new Array(i, parseFloat(jsondata[i]));
//var array_need = new Array( parseFloat(json[i]));
// jsondata.push(array_need);
//alert(array_need);
}
//});
//$.each(list, function (i, table) {
//for (var i in json)
// {
//var serie = [];
//jsondata.push(json[i].PLANNEDVISITS);
//jsondata.push(json[i].One);
//jsondata.push(parseFloat(serie));
// alert(jsondata);
//alert(serie);
//jsondata.push(table[i].PLANNED);
//alert(jsondata);
//jsondata.push(parseFloat(serie));
//alert(jsondata);
//}
//);
var data = google.visualization.arrayToDataTable
(jsondata);
var options = {
title: 'Planned Visit'
};
var chart = new google.visualization.PieChart(document.getElementById('Pie'));
chart.draw(data, options);
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string PIECHART(string date, string Level1, string Level2, string Level3, string Level4, string Level5, string Level6, string EmployeeId)
{
JavaScriptSerializer _jss = new JavaScriptSerializer();
string result = string.Empty;
string r = string.Empty;
try
{
#region Initialize
var PieChart = new System.Data.DataSet();
_nvCollection.Clear();
PieChart.Clear();
int year = 0, month = 0;
double employeeId = 0;
if (Level6 != "0")
{
employeeId = Convert.ToInt64(EmployeeId);
}
else
{
employeeId = 0;
}
#endregion
#region Set Year + Month
if (date != "")
{
year = Convert.ToDateTime(date).Year;
month = Convert.ToDateTime(date).Month;
}
else
{
year = DateTime.Now.Year;
month = DateTime.Now.Month;
}
#endregion
#region Filter By Role
//_nvCollection.Add("@Level3id-int", Level3.ToString());
//_nvCollection.Add("@Level4id-int", Level4.ToString());
//_nvCollection.Add("@Level5id-int", Level5.ToString());
//_nvCollection.Add("@Level6id-int", Level6.ToString());
_nvCollection.Add("@EmpId-int", EmployeeId.ToString());
_nvCollection.Add("@Month-int", Convert.ToString(month));
_nvCollection.Add("@Year-int", Convert.ToString(year));
PieChart = GetData("sp_PlannedVisits", _nvCollection);
#endregion
if (PieChart != null)
{
if (PieChart.Tables[0].Rows.Count > 0)
{
r = PieChart.Tables[0].ToJsonString();
}
}
}
catch (Exception e)
{
}
// return r;
return result = _jss.Serialize(r);
}
这是我的代码,用于将来自存储过程的动态数据显示为饼图。 Web服务正在被正确命中,但由于绘图(数据)功能,我无法显示饼图。 我曾尝试过你能做的一切。答案将不胜感激。