Packy
Packy

Reputation: 3573

array of numbers to integers

I know there might be an easy way but I can not get this to work. Basically I am striping the values from an Associative Array and just creating another array of those values. Then I need to use those numbers as the data value from my chart.js graph.

Here is what I need:

data: [ 50,0,50,200 ]

This works when I hard code the numbers for the data

Here is what I have that doesn't work:

var categoryData = <?php echo (json_encode($categories)) ?>;
var categoryGraph = [];

$.each(categoryData, function (key, data) {
     categoryGraph.push(data);
});

console.log( categoryGraph.join() );

////Then the data I do like this

data: [ categoryGraph.join() ],

Console displays : 50,0,50,200

I assume that because categoryGraph.join() outputs a string when data is looking for ints

Upvotes: 0

Views: 34

Answers (1)

castletheperson
castletheperson

Reputation: 33466

Use the array itself as the value for data:

data: categoryGraph,

Upvotes: 1

Related Questions