Answer the question
In order to leave comments, you need to log in
How to display an array in google charts?
As a result of foreach php I collect an array for its further output in the chart.
But the output cannot be made, I get the error Data column(s) for axis #0 cannot be of type string .
I posted an example here: https://jsfiddle.net/xpvt214o/416806/
Tell me what's the problem?
Answer the question
In order to leave comments, you need to log in
It is not clear why you are making JSON from an array and passing it to lib. Just pass your array to google.visualization.arrayToDataTable and whatever it returns, pass it to draw. Also, the Expenses column should be numeric and not string.
Working code
arr =[];
arr.push(['Days', 'Sales', 'Expenses']);
arr.push(["12.07.2018", 1, 15000]);
arr.push(["13.07.2018", 1, 12000]);
arr.push(["14.07.2018", 1, 18000]);
arr.push(["15.07.2018", 1, 6000]);
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(arr);
var options = {
title: 'Даты и заказы',
hAxis: {title: 'Year', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('graph_1'));
chart.draw(data, options);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question