0

I'm trying to pass php array to my jQuery function, I have done and working properly and I'm facing formatting issues. Below are details.

Default function

drawHeroArea : function () {

    !verboseBuild || console.log('proton.graphsStats.drawHeroArea()');
    if($('#hero-area').length)

    proton.graphsStats.graph.Area = Morris.Area({

        element: 'hero-area',

        data: [

          {period: '2010Apr Q1', iphone: 2666, ipad: null, itouch: 2647},

          {period: '2010 Q2', iphone: 2778, ipad: 2294, itouch: 2441},

          {period: '2010 Q3', iphone: 4912, ipad: 1969, itouch: 2501},

          {period: '2010 Q4', iphone: 3767, ipad: 3597, itouch: 5689},

          {period: '2011 Q1', iphone: 6810, ipad: 1914, itouch: 2293},

          {period: '2011 Q2', iphone: 5670, ipad: 4293, itouch: 1881},

          {period: '2011 Q3', iphone: 4820, ipad: 3795, itouch: 1588},

          {period: '2011 Q4', iphone: 15073, ipad: 5967, itouch: 5175},

          {period: '2012 Q1', iphone: 10687, ipad: 4460, itouch: 2028},

          {period: '2012 Q2', iphone: 8432, ipad: 5713, itouch: 1791}

        ],

        xkey: 'period',

        ykeys: ['iphone', 'ipad', 'itouch'],

        labels: ['iPhone', 'iPad', 'iPod Touch'],

        pointSize: 2,

        hideHover: 'auto'

    });

},

I want to pass data in this function

 $LoopD['mydata'] = array();
 foreach($tData as $mon=>$val){ 

        $LoopD[]  =  array(

        'period' => $mon, 
        'iphone' => $val['amber'], 
        'ipad' =>  $val['red'],
        'itouch' => $val['green'],
            );

}
$jsonL  = json_encode($LoopD);  

Javascript:

var jsonL       = $jsonL;

$(document).ready(function(e) {
            drawHeroArea(jsonL);

                });

I'm passing data to function

drawHeroArea : function (jsonL) {

        !verboseBuild || console.log('proton.graphsStats.drawHeroArea()');
        if($('#hero-area').length)

        proton.graphsStats.graph.Area = Morris.Area({

            element: 'hero-area',

            data: [
            jsonL
],

            xkey: 'period',

            ykeys: ['iphone', 'ipad', 'itouch'],

            labels: ['iPhone', 'iPad', 'iPod Touch'],

            pointSize: 2,

            hideHover: 'auto'

        });

    }

I have tried so far but unable to find result i want data folksinging format in my jquery function.

{period: '2010 Q2', iphone: 2778, ipad: 2294, itouch: 2441}
1

1 Answer 1

1

jsonL already is an array, so in your drawHeroArea instead of this:

data: [
    jsonL
],

use this:

data: jsonL

Also make sure you replace this:

$LoopD['mydata'] = array();

With this:

$LoopD = array();
Sign up to request clarification or add additional context in comments.

2 Comments

@ayazkhan sorry - I edited my answer - I missed another line that needs to be replaced.
I have tried as you told me but still unable to failed to get result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.