0

I'm traying to create an chart by points by points. Not live or someting special. It might be a basic thing but during 2 days I can't find or understand a solution.

PHP Code

for ($i = 0;$i < $numResults; $i++)
        {
            $row = $result->fetch_assoc();

            array_push($returnArray,array($row['powerWeek'] => $row['powerPower'] ));

        }
        echo json_encode($returnArray);

PHP Result: [{"1":"51"},{"2":"52"},{"3":"52"}]

JavaScipt Code:

 $.getJSON('getPower.php',function(getJSONText)
    {   
        var series = {};    
        $.each(getJSONText, function(key, value) {  
            series.data = value;
            option.series.push(series);

        });
        var chart = new Highcharts.Chart(option); 
}); 

However graph not been drawn. Thanks for all help.

1 Answer 1

2

I solved my problem. In php code i add intval fonction while building the array, and i changed it to multi-dimensiyon array:

if  ($numResults != 0)
    {
        for ($i = 0;$i < $numResults; $i++)
        {
            $row = $result->fetch_assoc();

            array_push($returnArray,array(intval($row['powerWeek']) , intval($row['powerPower']) ));

        }
        echo json_encode($returnArray); 
    }
}

And I edit my JavaScript code to this :

function requestData(){
    $.getJSON('getPower.php',function(getJSONText)
        {   
         chart.series[0].setData(getJSONText, true);
        });
}
Sign up to request clarification or add additional context in comments.

Comments

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.