I am trying to pass an array of numbers to google charts, this array is pulled by this code from a div with class .likescount
var i, $mvar = $('.likescount'); // using the $ prefix to use the "jQuery wrapped var" convention function logit( string ) { var text = document.createTextNode( string ); $('.alllikesinrow').append(text); $('.alllikesinrow').append("<br>"); } logit($mvar.length); for (i=0; i<$mvar.length; i++) { logit($mvar.eq(i).html()); }
The array works because I use append to print it and its work, the hard part is to pass this data to data.addRows, heres the complete code that I use worked around it, but never received it, I follow this guy that got it how to add data to google charts using javascript? but without luck any help wold would be great.
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['line']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var i, $mvar = $('.likescount'); // using the $ prefix to use the "jQuery wrapped var" convention x = []; for (i=0; i<$mvar.length; i++ ) { x.push( ['1', parseFloat($($mvar[i]).text())] ); } var data = new google.visualization.DataTable(); data.addColumn('string', 'Day'); data.addColumn('number', 'Likes'); data.addRows(x); var options = { chart: { title: 'Likes vs Comentarios', subtitle: 'Data Magnus by Optimum' }, height: 500 }; var chart = new google.charts.Line(document.getElementById('curve_chart')); chart.draw(data, google.charts.Line.convertOptions(options), {pointSize: 1}); } </script>
Thanks Rodrigo
EDIT: Edited by a working press of WhiteHat
source share