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?
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
twoDOuterArraybut you are passing itdatawhich 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.