line chart with dates in php and mysql

142 views
Skip to first unread message

Joao castro pereira

unread,
Oct 4, 2018, 7:25:09 PM10/4/18
to Google Visualization API
im developing a chart that show the price evolution over time.

When i was developing in my local server i could use a php while inside de script.. but after deployment for online server it no longer works.

the code i have now is:

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js">
        
        
 



    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
          
          var data = new google.visualization.DataTable();
      data.addColumn('date', 'Team');
      data.addColumn('value', 'Season Start Date');
        data.addRows(
        
          
        
          
          <?php echo $dados;?>

        ]);

       

        var options = {

'backgroundColor': 'transparent',
'curveType': 'function',
'is3D':true
};

        var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

        chart.draw(data, options);
      }
    </script>

notice that the output from my $dados is:

[2018-09-06, 2.00],[2018-09-07, 2.00],[2018-09-07, 2.10],[2018-09-08, 2.00],[2018-09-12, 2.95],[2018-09-12, 2.00],[2018-09-13, 2.10],[2018-09-13, 2.10],[2018-10-04, 2.10],[2018-10-04, 2.10],[2018-10-04, 2.10],

but still no idea why it isn't working...

help please!!

Joao castro pereira

unread,
Oct 4, 2018, 7:30:02 PM10/4/18
to Google Visualization API
i've notice that i was missing a [ after the data rows, corrected it, but stil doesn't work...

Daniel LaLiberte

unread,
Oct 4, 2018, 8:29:56 PM10/4/18
to Google Visualization API
Could you put together a jsfiddle with some sample data (to replace your php inlining) that shows what you are experiencing?  

On Thu, Oct 4, 2018 at 7:30 PM Joao castro pereira <joao.cast...@gmail.com> wrote:
i've notice that i was missing a [ after the data rows, corrected it, but stil doesn't work...

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@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/d4448f7d-516e-42c4-ae07-b02a85e15771%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Joao castro pereira

unread,
Oct 5, 2018, 2:30:35 PM10/5/18
to Google Visualization API
Will do that asap

Joao castro pereira

unread,
Oct 5, 2018, 3:56:00 PM10/5/18
to Google Visualization API


sexta-feira, 5 de Outubro de 2018 às 01:29:56 UTC+1, Daniel LaLiberte escreveu:
Could you put together a jsfiddle with some sample data (to replace your php inlining) that shows what you are experiencing?  

On Thu, Oct 4, 2018 at 7:30 PM Joao castro pereira <joao.cast...@gmail.com> wrote:
i've notice that i was missing a [ after the data rows, corrected it, but stil doesn't work...

--
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 google-visualization-api+unsub...@googlegroups.com.

Daniel LaLiberte

unread,
Oct 5, 2018, 4:11:47 PM10/5/18
to Google Visualization API
Yes, that's what I asked for.  However, I should have read your post a little more carefully.  You say the problem occurs once you try to generate the same script from your server.  In that case, the thing to do is to view the source of the page that is generated and compare carefully with what you intended to do.  Something must be different.

Also, I notice that your domain data is probably not what you intended.  You have values like: 2018-09-06, which means the arithmetic expression that subtracts two numbers from 2018.  You need to use a date format.  See:  https://developers.google.com/chart/interactive/docs/datesandtimes


On Fri, Oct 5, 2018 at 3:56 PM Joao castro pereira <joao.cast...@gmail.com> wrote:
i believe this is what you asked...

https://jsfiddle.net/castropereira/9oe7510v/5/#&togetherjs=3230sq5BCo

sexta-feira, 5 de Outubro de 2018 às 01:29:56 UTC+1, Daniel LaLiberte escreveu:
Could you put together a jsfiddle with some sample data (to replace your php inlining) that shows what you are experiencing?  

On Thu, Oct 4, 2018 at 7:30 PM Joao castro pereira <joao.cast...@gmail.com> wrote:
i've notice that i was missing a [ after the data rows, corrected it, but stil doesn't work...

--
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 google-visualizati...@googlegroups.com.

--
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 google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.


--

Joao castro pereira

unread,
Oct 11, 2018, 12:39:39 PM10/11/18
to Google Visualization API
just solved my problem....


now i just have a question...

all the data is correct... but the chart is showing month+1???

any guess???

Daniel LaLiberte

unread,
Oct 11, 2018, 12:47:23 PM10/11/18
to Google Visualization API
Month numbers start at 0, when you are specifying dates either with JS Date constructors or date string notation, e.g. "Date(yyyy, mm, dd)".  


--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.

Joao castro pereira

unread,
Oct 11, 2018, 12:47:38 PM10/11/18
to Google Visualization API
just notice that google charts is 0 based.... so just put -1 when getting the result!


sexta-feira, 5 de Outubro de 2018 às 00:25:09 UTC+1, Joao castro pereira escreveu:

Joao castro pereira

unread,
Oct 11, 2018, 12:48:26 PM10/11/18
to Google Visualization API
that's what i found in stack overflow!

thank you for your help! just added a -1!

Ryan Anderson

unread,
Oct 12, 2018, 10:49:56 AM10/12/18
to google-visua...@googlegroups.com
unsubscribe

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
Reply all
Reply to author
Forward
0 new messages