0
I have the following Chart combo:
<div id="vendas_diarias" style="height: 500px;"></div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Create the data table for Sarah's pizza.
var data = new google.visualization.DataTable();
data.addColumn('string', 'DATA');
data.addColumn('number', 'VENDAS');
data.addColumn('number', 'METAS');
data.addRows([
['<?php echo"$var_d01";?>',<?php echo"$var_vda_d01";?>,<?php echo"$var_mta_d01";?>],
['<?php echo"$var_d02";?>',<?php echo"$var_vda_d02";?>,<?php echo"$var_mta_d02";?>],
['<?php echo"$var_d03";?>',<?php echo"$var_vda_d03";?>,<?php echo"$var_mta_d03";?>],
['<?php echo"$var_d04";?>',<?php echo"$var_vda_d04";?>,<?php echo"$var_mta_d04";?>],
['<?php echo"$var_d05";?>',<?php echo"$var_vda_d05";?>,<?php echo"$var_mta_d05";?>],
['<?php echo"$var_d06";?>',<?php echo"$var_vda_d06";?>,<?php echo"$var_mta_d06";?>],
['<?php echo"$var_d07";?>',<?php echo"$var_vda_d07";?>,<?php echo"$var_mta_d07";?>],
['<?php echo"$var_d08";?>',<?php echo"$var_vda_d08";?>,<?php echo"$var_mta_d08";?>],
['<?php echo"$var_d09";?>',<?php echo"$var_vda_d09";?>,<?php echo"$var_mta_d09";?>],
['<?php echo"$var_d10";?>',<?php echo"$var_vda_d10";?>,<?php echo"$var_mta_d10";?>],
['<?php echo"$var_d11";?>',<?php echo"$var_vda_d11";?>,<?php echo"$var_mta_d11";?>],
['<?php echo"$var_d12";?>',<?php echo"$var_vda_d12";?>,<?php echo"$var_mta_d12";?>],
['<?php echo"$var_d13";?>',<?php echo"$var_vda_d14";?>,<?php echo"$var_mta_d13";?>],
['<?php echo"$var_d14";?>',<?php echo"$var_vda_d14";?>,<?php echo"$var_mta_d14";?>],
['<?php echo"$var_d15";?>',<?php echo"$var_vda_d15";?>,<?php echo"$var_mta_d15";?>],
['<?php echo"$var_d16";?>',<?php echo"$var_vda_d16";?>,<?php echo"$var_mta_d16";?>],
['<?php echo"$var_d17";?>',<?php echo"$var_vda_d17";?>,<?php echo"$var_mta_d17";?>],
['<?php echo"$var_d18";?>',<?php echo"$var_vda_d18";?>,<?php echo"$var_mta_d18";?>],
['<?php echo"$var_d19";?>',<?php echo"$var_vda_d19";?>,<?php echo"$var_mta_d19";?>],
['<?php echo"$var_d20";?>',<?php echo"$var_vda_d20";?>,<?php echo"$var_mta_d20";?>],
['<?php echo"$var_d21";?>',<?php echo"$var_vda_d21";?>,<?php echo"$var_mta_d21";?>],
['<?php echo"$var_d22";?>',<?php echo"$var_vda_d22";?>,<?php echo"$var_mta_d22";?>],
['<?php echo"$var_d23";?>',<?php echo"$var_vda_d23";?>,<?php echo"$var_mta_d23";?>],
['<?php echo"$var_d24";?>',<?php echo"$var_vda_d24";?>,<?php echo"$var_mta_d24";?>],
['<?php echo"$var_d25";?>',<?php echo"$var_vda_d25";?>,<?php echo"$var_mta_d25";?>],
['<?php echo"$var_d26";?>',<?php echo"$var_vda_d26";?>,<?php echo"$var_mta_d26";?>],
['<?php echo"$var_d27";?>',<?php echo"$var_vda_d27";?>,<?php echo"$var_mta_d27";?>],
['<?php echo"$var_d28";?>',<?php echo"$var_vda_d28";?>,<?php echo"$var_mta_d28";?>],
['<?php echo"$var_d29";?>',<?php echo"$var_vda_d29";?>,<?php echo"$var_mta_d29";?>],
['<?php echo"$var_d30";?>',<?php echo"$var_vda_d30";?>,<?php echo"$var_mta_d30";?>],
['<?php echo"$var_d31";?>',<?php echo"$var_vda_d31";?>,<?php echo"$var_mta_d31";?>]
]);
var options = {
title : 'VENDAS DIARIAS',
vAxis: {title: 'PERCENTUAL'},
hAxis: {title: 'DIAS'},
seriesType: 'bars',
series: {1: {type: 'line'}}
};
var chart = new google.visualization.ComboChart(document.getElementById('vendas_diarias'));
chart.draw(data, options);
}
</script>
Each line represents 1 day of the month, so it is necessary to display the lines until the current day, example: As today are 23 I need to display from the line:
['<?php echo"$var_d01";?>',<?php echo"$var_vda_d01";?>,<?php echo"$var_mta_d01";?>],
To the line:
['<?php echo"$var_d23";?>',<?php echo"$var_vda_d23";?>,<?php echo"$var_mta_d23";?>],
How could I do that?
It worked out the way it needed, only one more doubt,example,the day 23 that is today was without launching,with that was returning this error,by has no information and Chart be blank, could pass some condition ? to deal with this type of error?
– Chefe Druida
<br /> <b>Notice</b>: Undefined variable: var_d23 in <b>C: xampp htdocs big bigbi vendas_acum.php</b> on line <b>80</b><br /> [',102.995854,73.333333333326]
– Chefe Druida
you can put the echo inside a
if isset(${'var_d'.str_pad($i, 2,'0', STR_PAD_LEFT) })
which will only print if the variable exists...– Jader A. Wagner
Perfect, Thank you again
– Chefe Druida