【发布时间】:2015-09-09 11:54:37
【问题描述】:
我正在开展一个使用数据生成“Highcharts”图的项目。基本上,它只是一个 x/y 线图,但图表使用了错误的 x 轴数据。我试图弄清楚为什么会发生这种情况。我的sn-p代码如下:
var data = this.costAnalyzerService.OpenCostWindow(DataToSend, CurrentTrain, CustId);
var obj = Json(data, JsonRequestBehavior.AllowGet);
return obj;
“数据”变量的类型为Systems.Collections.Generic.List<System.Tuple<int, double, double>>
基本上,这个变量中的所有数据都是正确的。 int 应该是我的 x 轴,两个双打是我的两组线系列数据。我有理由相信生成绘图的代码没有使用“int”作为 x 轴。相反,它只是使用 1,2,3...,N 个点作为 x 轴编号。
如何查看这个“JSON”对象以查看正在发生的事情以及它返回的内容。如果我在这一点上单步执行代码,图表只会生成并且应用程序的执行完成。在此之后没有更多的步骤点要调试。从字面上看,该函数返回 JSON 对象并完成。据我所知,它甚至不会返回调用函数。
这是我正在使用的 COMPLETE 方法:
public JsonResult PlotCostAnalyzerChart(double acidPrice = 0.0, double causticPrice = 0.0, int acidUsage = 0, int causticUsage = 0, int cationResin = 0, int anionResin = 0, bool loadOnSettingsUpdate = false)
{
try
{
PriceData DataToSend = this.Session["Data_ToSend"] != null ? Session["Data_ToSend"] as PriceData : new PriceData();
string CustId = this.Session["CustomerId"] != null ? Session["CustomerId"].ToString() : string.Empty;
if (loadOnSettingsUpdate)
{
DataToSend.AcidPrice = acidPrice;
DataToSend.CausticPrice = causticPrice;
DataToSend.AcidUsage = acidUsage;
DataToSend.CausticUsage = causticUsage;
DataToSend.AmountCation = cationResin;
DataToSend.AmountAnion = anionResin;
}
else
{
DataToSend.AcidUsage = 6;
DataToSend.CausticUsage = 6;
DataToSend.AmountCation = 600;
DataToSend.AmountAnion = 600;
}
int CurrentTrain = 1;//set the current train in scope
//if (Session["SelectedTrain"]!=null)
//{
// CurrentTrain = int.Parse(Session["SelectedTrain"].ToString());
//}
var data = this.costAnalyzerService.OpenCostWindow(DataToSend, CurrentTrain, CustId);
var obj = Json(data, JsonRequestBehavior.AllowGet);
return obj;
}
catch
{
throw;
}
}
非常感谢您的意见、建议和建议!
这是一些我认为正在生成情节的 java 脚本:
$(function () {
$.ajax({
url: 'PlotCostAnalyzerChart',
type: "GET",
dataType: "json",
success: function (jsonData) {
$.ajax({
url: 'GetCumulativeSavings',
type: 'GET',
success: function (CumulativeSavingsData) {
$("#CumulativeSavings").empty();
$("#CumulativeSavings").html(CumulativeSavingsData);
},
error: function (xhr) {
window.location.href = "/ClientDatabase/Errorview";
}
});
var arrxaxis = new Array();
var arrWithOutClean = new Array();
var arrWithClean = new Array();
for (var i = 0 ; i < jsonData.length ; i++) {
var mxaxis = new Object();
var mWithOutClean = new Object();
var mWithClean = new Object();
mxaxis = jsonData[i];
mWithOutClean = jsonData[i];
mWithClean = jsonData[i];
arrxaxis.push(mxaxis.Item1);
arrWithOutClean.push(mWithOutClean.Item2);
arrWithClean.push(mWithClean.Item3);
}
//alert(arr);
$('#graph_CostAnalyzer').empty();
$('#graph_CostAnalyzer').highcharts({
chart: {
zoomType: 'x'
},
title: {
text: 'Cost Analyzer',
x: -20 //center
},
xAxis: {
title: {
text: 'Number of Weeks'
}
},
yAxis: {
title: {
text: 'Cost of Operations'
}
},
credits: {
enabled: false
},
tooltip: {
crosshairs: true,
formatter: function () {
return 'Week Number : ' + this.point.x + '<br>' + this.series.name + ' : ' + Highcharts.numberFormat(this.point.y, 2) + '<br>' + 'Click on chart to get cost analysis';
}
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function (e) {
$("#CostAnalyzerResultsTable").fadeOut(300);
$.ajax({
url: 'GetResultsTable',
type: "GET",
data: { weekNumber: this.x },
success: function (CostAnalyzerResultsData) {
//alert(CostAnalyzerResultsData);
$("#CostAnalyzerResultsTable").empty();
$("#CostAnalyzerResultsTable").html(CostAnalyzerResultsData);
//FADEOUT AND FADEIN
$("#CostAnalyzerResultsTable").fadeIn(400);
}
});
}
}
},
marker: {
lineWidth: 1
}
}
},
legend:{
enabled: true,
layout: 'horizontal',
borderWidth: 1
},
series: [{
name: 'With RTI Cleaning',
data: arrWithClean
},
{
name: 'Without RTI Cleaning',
data: arrWithOutClean
}]
});
}
});
});
【问题讨论】:
-
您确定您的代码正在生成 highcharts 所需的正确 json 吗?
-
不,我不是。我不确定如何查看生成的 JSON 代码。当我向“obj”变量添加“watch”时,我看到的只是:{System.Web.Mvc.JsonResult}。我不确定如何查看内容。
-
你在哪里填充图表?
-
这是在网页上,我要补充一些细节,显然我找到了一个绘制图表的java-script,但我对此非常陌生,visual studio似乎没有步骤通过这部分代码,以便我可以看到发生了什么..
-
而
var mxaxis = new Object(); mxaxis = jsonData[i];是不必要的。你可以这样做arrxaxis.push(jsonData[i].Item1);
标签: javascript c# json highcharts