1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Mülheim an der Ruhr, Germany
    Posts
    79
    Vote Rating
    0
    Answers
    5
    blade226 is on a distinguished road

      0  

    Default Answered: column chart: json Problem

    Answered: column chart: json Problem


    Hi,
    i want to send a json-string and build a column-chart.

    I despair to build the string.

    I have following varaibles:
    Code:
    team = "Team1";
    anzahl = $team1;
    
    team = "Team2";
    anzahl = $team2;
    
    team = "Team3";
    anzahl = $team3;
    and so on......
    I want to sent this json-string from php:
    Code:
    data:[
            { 'team': 'Team1','anzahl':2400 },
            { 'team': 'Team2','anzahl':1168 },
            { 'team': 'Team3','anzahl':2391 },
            { 'team': 'Team4','anzahl':1802 },
            { 'team': 'Team5','anzahl':2156 },
            { 'team': 'Team6','anzahl':2696 }
                    ]
    How to build?

    THX!

  2. I find the solution:

    Code:
    $obj = new StdClass();
    $obj->team = 'Team1';
    $obj->anzahl = $team1;
    
    $obj2 = new StdClass();
    $obj2->team = 'Team2';
    $obj2->anzahl = $team2;
    
    $obj3 = new StdClass();
    $obj3->team = 'Team3';
    $obj3->anzahl = $team3;
    
    $obj4 = new StdClass();
    $obj4->team = 'Team4';
    $obj4->anzahl = $team4;
    
    $obj5 = new StdClass();
    $obj5->team = 'Team5';
    $obj5->anzahl = $team5;
    
    $obj6 = new StdClass();
    $obj6->team = 'Team6';
    $obj6->anzahl = $team6;
    
    $mydata = array($obj, $obj2, $obj3, $obj4, $obj5, $obj6);
    echo json_encode($mydata);

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,197
    Vote Rating
    482
    Answers
    690
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You can use something like:

    Code:
    $return = array(
        'success' => TRUE,
        'data' => $data // array 
    );
      
    $return = json_encode($return);
    echo $return;
    Scott

  4. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Mülheim an der Ruhr, Germany
    Posts
    79
    Vote Rating
    0
    Answers
    5
    blade226 is on a distinguished road

      0  

    Default


    Hi,
    thx for reply!

    But:
    data is result which should arrive in ext

    Code:
    data:[
    { 'team': 'Team1','anzahl':2400 },
    { 'team': 'Team2','anzahl':1168 },
    { 'team': 'Team3','anzahl':2391 },
    { 'team': 'Team4','anzahl':1802 },
    { 'team': 'Team5','anzahl':2156 }, 
    { 'team': 'Team6','anzahl':2696 }
    ]
    How can i write it in $data? It shows me in string special character for example "

  5. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Mülheim an der Ruhr, Germany
    Posts
    79
    Vote Rating
    0
    Answers
    5
    blade226 is on a distinguished road

      0  

    Default


    I find the solution:

    Code:
    $obj = new StdClass();
    $obj->team = 'Team1';
    $obj->anzahl = $team1;
    
    $obj2 = new StdClass();
    $obj2->team = 'Team2';
    $obj2->anzahl = $team2;
    
    $obj3 = new StdClass();
    $obj3->team = 'Team3';
    $obj3->anzahl = $team3;
    
    $obj4 = new StdClass();
    $obj4->team = 'Team4';
    $obj4->anzahl = $team4;
    
    $obj5 = new StdClass();
    $obj5->team = 'Team5';
    $obj5->anzahl = $team5;
    
    $obj6 = new StdClass();
    $obj6->team = 'Team6';
    $obj6->anzahl = $team6;
    
    $mydata = array($obj, $obj2, $obj3, $obj4, $obj5, $obj6);
    echo json_encode($mydata);

Thread Participants: 1