[英]mvc c# unable to plot flot chart, json data not valid?
我有控制器需要数据库数据并将json返回到javascript,但是我有一个问题,我无法显示图表,但无法显示条,我尝试了不同的方法,现在我需要您的帮助!
控制器:
foreach (Dashboard item in result)
{
DateTime kint = Convert.ToDateTime(item.date);
String dd = kint.Day.ToString();
stats.Add(new ReferralStat {data = Convert.ToInt16(item.percentage), label = "" + dd + ""});
perc.Add(new AccupancyPerc {data = Convert.ToInt16(item.percentage), label = Convert.ToInt16(dd)});
arr.Add(new Tuple<int, int>(Convert.ToInt16(dd), Convert.ToInt16(item.percentage)));
percent.Add(Convert.ToInt16(item.percentage));
json_string = json_string + "[" + dd + ", 100], ";
};
我试图恢复不同的格式:stat / perc / arr / percent
return Json(stats, "application/json", JsonRequestBehavior.AllowGet);
JavaScript:
function chartWeek(placeholder) {
var chartdata = [];
$(function () {
`$`.getJSON('../../Home/WeekAccupancy', function (chart_data) {
console.log(chart_data);
$.plot(placeholder, chart_data, {
series: {
pie: {
show: true,
innerRadius: .4,
stroke: {
width: 4,
color: "#F9F9F9"
},
label: {
show: true,
radius: 3 / 4,
formatter: donutLabelFormatter
}
},
},
legend: {
show: true
},
grid: {
hoverable: true
},
colors: ["#7d939a", "#5399D6", "#d7ea2b"],
})
//alert(chart_data);
});
});
}
似乎您的图表配置错误。 您需要将图表数据放入图表配置中,它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.