Question

<script>
// Data Values for the chart.

var newArray = new Array();
var newArray = <?php echo json_encode($values); ?>;

// Bar Chart.
if($("#chart-3").length > 0)
{

    var data = [];          
    for( var i = 0; i < newArray.length; i++)
    {
        data[i] = { data: newArray[i]}; // this causing problem.
        console.log(data[i]);
    }

    $.plot($("#chart-3"), data, 
    {
        series:
        {
            pie: { show: true }
        },
        legend: { show: false }
    });
}
</script>

If i put 4 in place of newArray[i] then graph is displaying values. I used the console.log() to check what values i am getting in newArray and what i am getting is:

console.log() output:

Object {data: "4"}
Object {data: "2"}
Was it helpful?

Solution

To ensure the numeric value is indeed numeric and not a string, you could do this:

data[i] = { data: parseInt(newArray[i])};

or use parseFloat if that is more appropriate.

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