Because months are zero-indexed in JavaScript. January is month 0, and
August is month 7.

Jon

On Fri, Jul 20, 2018 at 3:19 AM, Bevan Robinson <[email protected]>
wrote:

> The latest row in my database is 2018-07-20 but on the graph it shows as
> 20 Aug 2018
>
> Why?
>
>
> <script>
>>
>> google.charts.load('current', {'packages':['line', 'corechart']});
>>
>> google.charts.load('current', {'packages':['gauge']});
>>
>> google.charts.setOnLoadCallback(drawChart);
>>
>> google.charts.setOnLoadCallback(drawChart2);
>>
>>
>>> function drawChart() {
>>
>> var data = new google.visualization.DataTable();
>>
>>       data.addColumn('date', 'Date');
>>
>>       data.addColumn('number', 'Ph');
>>
>>       data.addColumn('number', 'Ammonia');
>>
>>       data.addColumn('number', 'Nitrite');
>>
>>       data.addColumn('number', 'Nitrate');
>>
>>       data.addColumn('number', 'Gravity');
>>
>>       data.addColumn('number', 'Phosphate');
>>
>>
>>
>>   data.addRows([
>>
>> <?php
>>
>> require 'db.php';
>>
>> $result = mysqli_query($link2, "SELECT * FROM `tank` ORDER BY `entryDate`
>>> asc");
>>
>> $num_rows = mysqli_num_rows($result);
>>
>> $i = 1;
>>
>> while ($row = $result->fetch_assoc()){
>>
>> $ph = $row['ph'];
>>
>> $amm = $row['ammonia'];
>>
>> $rite = $row['nitrite'];
>>
>> $rate = $row['nitrate'];
>>
>> $grav = $row['gravity'];
>>
>> $phos = $row['phosphate'];
>>
>> $n = $row['notes'];
>>
>> $date = DateTime::createFromFormat("Y-m-d", $row['entryDate']);
>>
>> $y = $date->format("Y");
>>
>> $m = $date->format("n");;
>>
>> $d = $date->format("d");
>>
>>
>>> echo "[ new Date($y, $m, $d), $ph, $amm, $rite, $rate, $grav, $phos ]";
>>
>> $i++;
>>
>> if ($i <= $num_rows){
>>
>> echo ",";
>>
>> }
>>
>> }
>>
>> ?>
>>
>>
>>> ]);
>>
>>
>>> var options = {
>>
>>   title: 'Company Performance',
>>
>>   curveType: 'function',
>>
>>   legend: { position: 'bottom' }
>>
>> };
>>
>>
>>> var materialOptions = {
>>
>>         chart: {
>>
>>           title: 'Average Temperatures and Daylight in Iceland Throughout
>>> the Year'
>>
>>         },
>>
>>         width: 900,
>>
>>         height: 900,
>>
>>         series: {
>>
>>           // Gives each series an axis name that matches the Y-axis below.
>>
>>           0: {axis: 'Temps'},
>>
>>           1: {axis: 'Daylight'}
>>
>>         },
>>
>>         axes: {
>>
>>           // Adds labels to each axis; they don't have to match the axis
>>> names.
>>
>>           y: {
>>
>>             Temps: {label: 'Temps (Celsius)'},
>>
>>             Daylight: {label: 'Daylight'}
>>
>>           }
>>
>>         }
>>
>>       };
>>
>>
>>> var chart = new google.visualization.LineChart(document.
>>> getElementById('curve_chart'));
>>
>> chart.draw(data, options);
>>
>> }
>>
>>
>>> function drawChart2() {
>>
>> var data = google.visualization.arrayToDataTable([
>>
>>   ['Label', 'Value'],
>>
>>   ['Ph', 10]
>>
>> ]);
>>
>> var options = {
>>
>>   width: 400, height: 120,
>>
>>   redFrom: 90, redTo: 100,
>>
>>   yellowFrom:75, yellowTo: 90,
>>
>>   minorTicks: 1
>>
>> };
>>
>> var chart = new google.visualization.Gauge(document.getElementById('
>>> chart_div'));
>>
>> chart.draw(data, options);
>>
>> setInterval(function() {
>>
>>   data.setValue(0, 1, 40 + Math.round(60 * Math.random()));
>>
>>   chart.draw(data, options);
>>
>> }, 13000);
>>
>> }
>>
>> </script>
>>
>>
>>
>> <div class="guage">
>>
>> <div id="chart_div" style="width: 400px; height: 120px;"></div>
>>
>> </div>
>>
>>
>>> <div id="curve_chart" style="width: 1900px; height: 900px;"></div>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to google-visualization-api@
> googlegroups.com.
> Visit this group at https://groups.google.com/
> group/google-visualization-api.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-visualization-api/fd199767-fd42-42da-9e8d-
> f62e91178719%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/fd199767-fd42-42da-9e8d-f62e91178719%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CAJs5hDaFkX%3DeQ5Ap29nC-%3DMBo6VMgocGW2hSDoPBujJzsfe8QA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to