我有这个查询来从我的数据库中选择数据。
SELECT monthname(DATA), sum(val1) DESPESAS, sum(val2) RECEITAS
from (
SELECT DATA, val1, val2
from (SELECT DATA, loja_id, valor val1, 0 val2
from despesas WHERE YEAR(DATA) = YEAR(CURDATE()) AND loja_id = '1') s1
union
(SELECT DATA loja_id, 0 val1, valor val2
from receitas WHERE YEAR(DATA) = YEAR(CURDATE()) and loja_id = '1') ) t
group by month(DATA)
order by DATA
它会在这样的表中返回月总数:
MES - DESPESAS - RECEITAS
January - R$16,29 - R$355,00
February - R$120,00 - R$107,29
March - R$124,06 - R$0,00
April - R$0,00 - R$38,00
May - R$130,91 - R$37,00
July - R$0,00 - R$10,00
如何使用带有此值的Google图表生成图表:
cols = months and line 1 = despesas line 2 - receitas
我像这样手动生成
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Mes', 'Receitas', 'Despesas'],
['Janeiro', 0, 0],
['Fevereiro', 0, 0],
['Março', 1315.98, 0],
['Abril', 1066.08, 0],
['Maio', 1764.04, 0],
['Junho', 1875.59, 181.46],
['Julho', 1850.54, 2102.84],
['Agosto', 2980, 2527.6],
['Setembro', 0, 0],
['Outubro', 0, 0],
['Novembro', 0, 0],
['Dezembro', 0, 0]
]);
var options = {
title: 'Despesas e Receitas Almirante',
hAxis: {title: 'Mes', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0},
series: {
0: { color: '#0000FF' },
1: { color: '#FF0000' },
}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_Almirante'));
chart.draw(data, options);
}