【发布时间】:2016-03-08 16:27:07
【问题描述】:
虽然我已经通过将静态值写入我的 MVC 5 视图页面来成功创建 Highcharts Box-and-Whisker plot,但现在我正在尝试通过使用控制器中的 JsonResult 函数填充值来做同样的事情。
Highcharts 网站有一个关于custom preprocessing data using JSON 的部分,但到目前为止,我使用该 URL 中显示的方法没有成功,只是将图表类型更改为“boxplot”并定义参数。一个警告框显示从 JsonResult 函数中成功读取了数据值,但出现的图表没有我希望看到的数据。
我检查了 Firebug,在浏览器中查看页面时没有看到 jQuery 错误。
我在这里遗漏了一些明显的东西吗?我在 Visual Studio 中使用 MVC 5 C#。
@section scripts
{
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script>
$(function () {
var options = {
chart: {
renderTo: 'container',
type: 'boxplot'
},
series: [{}]
};
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("GetChartData")",
cache: false,
async: false,
data: { _campus: "@ViewBag.SelectedCampus",
_semester: "@ViewBag.SelectedSemester",
_fy: "FY12" },
success: function (data) {
options.series[0].data = data;
var chart = new Highcharts.Chart(options);
alert(data); // I see the correct array set in the alert box:
// as written literally: 395,441,457,479,532
},
error: function (jqXHR, textStatus, errorThrown) {
alert("oops: " + textStatus + ": " + jqXHR.responseText);
}
});
});
</script>
}
这是它的截图:
如果有什么不同,这里是 JsonResult 函数:
public JsonResult GetChartData(string _campus, string _semester, string _fy)
{
IEnumerable<MathAimsScaleScore> query = db.MathAimsScaleScores
.Where(m => m.Campus == _campus)
.Where(m => m.Semester == _semester)
.Where(m=>m.FY==_fy);
var FyList = query.Select(m => Convert.ToDouble(m.ScaleScore));
var jsonList = new double[5];
for (int i = 0; i < 5; i++)
{
jsonList[i] = Statistics.FiveNumberSummary(FyList)[i];
}
return Json(jsonList.ToArray());
}
【问题讨论】:
标签: c# jquery json asp.net-mvc highcharts