Packy Packy -5 years ago 162
jQuery Question

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

Here is what I have that doesn't work:

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

$.each(categoryData, function (key, data) {

console.log( categoryGraph.join() );

////Then the data I do like this

data: [ categoryGraph.join() ],

Console displays :

I assume that because
outputs a string when
is looking for ints

Answer Source

Use the array itself as the value for data:

data: categoryGraph,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download