jqplot 图表的多维数组
我正在尝试创建 Jqplot 条形图,并在创建多维数组时遇到困难,就像
var plot2 = $.jqplot('chart2', [
[[2,1], [4,2], [6,3], [3,4]],
[[5,1], [1,2], [3,3], [4,4]],
[[4,1], [7,2], [1,3], [2,4]]],
我的数据位于 hashMap 内的 HashMap 中一样,就像
{software={low=1,high=5, medium=4}, harware={low=3,high=3},network{low=3,high=3,medium=8}}
我如何解释上面的多维数组中的数据一样。
我编写了以下代码来实现此目的
$(document).ready(function(){
<c:forEach var="data" varStatus="main" items="${data}">
var cdata = new Array();
var twoDOuterArray = new Array(${data.size()});
<c:forEach var="mapEntry" varStatus="status" items="${data['cData']}">
twoDOuterArray[${status.index}] = new Array(3);
</c:forEach>
<c:forEach var="mapEntry" varStatus="status" items="${data['cData']}">
<c:forEach var="dataValue" varStatus="status2" items="${mapEntry.value}">
var valueArray = new Array();
alueArray.push(${dataValue.value});
valueArray.push("${mapEntry.key}");
twoDOuterArray[${status2.index}][${status.index}]=valueArray;
</c:forEach>
//alert(twoDOuterArray[${status.index}].length);
</c:forEach>
data.push(twoDOuterArray);
alert(twoDOuterArray);
plot2b = $.jqplot('chart2', data, {
seriesDefaults: {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
shadowAngle: 50,
rendererOptions: {
barDirection: 'horizontal'
}
},
title:{
text: "${title}",
show: true,
textColor:"#fff",
},
axes: {
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
},
legend: { show:true, location: 'e' }
});
);
</c:forEach>
});
似乎格式是正确的,但我不明白我错在哪里,或者这是创建数据的正确方法。如果有人能帮助我解决这个问题那就太好了。
编辑: 如何检查我的数组是否按照上述要求的格式创建?
I am trying to create Jqplot bar charts and facing difficulty in creating multidimensional array in like
var plot2 = $.jqplot('chart2', [
[[2,1], [4,2], [6,3], [3,4]],
[[5,1], [1,2], [3,3], [4,4]],
[[4,1], [7,2], [1,3], [2,4]]],
My data is in a HashMap inside hashMap it is like
{software={low=1,high=5, medium=4}, harware={low=3,high=3},network{low=3,high=3,medium=8}}
How I can interpret my data in above multidimensional array.
I have written the following code to achieve this
$(document).ready(function(){
<c:forEach var="data" varStatus="main" items="${data}">
var cdata = new Array();
var twoDOuterArray = new Array(${data.size()});
<c:forEach var="mapEntry" varStatus="status" items="${data['cData']}">
twoDOuterArray[${status.index}] = new Array(3);
</c:forEach>
<c:forEach var="mapEntry" varStatus="status" items="${data['cData']}">
<c:forEach var="dataValue" varStatus="status2" items="${mapEntry.value}">
var valueArray = new Array();
alueArray.push(${dataValue.value});
valueArray.push("${mapEntry.key}");
twoDOuterArray[${status2.index}][${status.index}]=valueArray;
</c:forEach>
//alert(twoDOuterArray[${status.index}].length);
</c:forEach>
data.push(twoDOuterArray);
alert(twoDOuterArray);
plot2b = $.jqplot('chart2', data, {
seriesDefaults: {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
shadowAngle: 50,
rendererOptions: {
barDirection: 'horizontal'
}
},
title:{
text: "${title}",
show: true,
textColor:"#fff",
},
axes: {
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
},
legend: { show:true, location: 'e' }
});
);
</c:forEach>
});
It seems that format is correct but I don't understand where I am wrong or is this the correct way to create data. if anyone could help me to solve this that would be great.
edit:
how I can check that my array is created in the above required format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要查看数据的样子,我将使用 Firebug(或您最喜欢的浏览器的等效浏览器)在对 jqplot 的调用上设置断点。然后检查您要检查的变量。
另外,似乎 jqplot 应该使用
twoDOuterArray
但您传递它data
这可能是一个问题。另一件事:如果您的原始数据对象包含多个元素,则您拥有的外部
将导致 jqplot 将新绘图覆盖在先前生成的绘图上。我还建议不要将 JSTL 与 Javascript 混合在一起,而是从设置其他变量的位置(例如:控制器)构建二维数组。然后使用 Gson 等库将对象转换为 JSON,并将其直接传递给 jqplot。
To see what your data looks like, I'd use Firebug (or your favorite browser's equivalent) to set a breakpoint on the call to jqplot. Then inspect the variable you want to check.
Also it seems jqplot should be using
twoDOuterArray
but you are passing itdata
which might be a problem.One more thing: if you original data object contains more than one element, the outer
<c:forEach>
you have will result in jqplot overlaying new plots on the previously generated ones.Instead of mixing the JSTL with the Javascript I would also suggest building your 2d array from wherever your other variables are set (for example: a controller). Then convert the object to JSON with a library like Gson and pass that to jqplot directly.