Question

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,medium=8},network{low=3,high=3,medium=8}}

How I can interpret my data in above multidimensional array. I tried using javascript splice method but it does not work the way I can't compare my jsp variable with javascript variable and it become mess that I can't post here. So is this better if I create this array in java itself and pass that to my jsp page. Please anyone put some light on it and what is the best way to achieve this format.

Was it helpful?

Solution

Here the data is sent as a javascript object. You can pass it as a JsArray like following

public JsArray<?> push( String[] labels, double[] y )
{
    JsArray<JsArrayMixed> Data = JavaScriptObject.createArray().cast();
    for ( int i = 0; i < y.length; i++ )
    {
        JsArrayMixed series = JavaScriptObject.createArray().cast();
        series.push( dateLabels[i] );
        series.push( y[i] );
        Data.push( series );`enter code here`
    }
    return Data;
}

So you can directly pass that data to jqplot function with options and chart div id

Pardon me.. For some reason that JsArray's push method just pushing values to right hand side with a comma even if we have nested small JsArryMixed like arrays. I think you can try on JSON arrays and pass it as a javascript object to the jqplot chart.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top