0

Think I finally got the data I want in the right form. I'm just not getting a graph. I'm using a scatter since I need time, ( hourly ). I'm pulling from mysql but I'm handing it to rgraph in the right format. I'm getting no error and no graph.

<script>
    chart = new RGraph.Scatter('cvs', [[2013-03-28 00:05, 0.00, 'red'], [2013-03-28    01:05, -2.00, 'red'], [2013-03-28 02:05, -2.58, 'red'], [2013-03-28 03:05, -3.90, 'red'], [2013-03-28 04:05, -5.53, 'red'], [2013-03-28 05:05, -7.58, 'red'], [2013-03-28 06:05, -6.26, 'red'], [2013-03-28 07:05, -3.63, 'red'], [2013-03-28 08:05, -4.78, 'red'], [2013-03-28 09:05, -4.29, 'red'], [2013-03-28 10:05, -3.69, 'red'], [2013-03-28 11:05, -3.27, 'red'], [2013-03-28 12:05, -4.23, 'red'], [2013-03-28 13:05, -5.02, 'red'], [2013-03-28 14:05, -4.50, 'red'], [2013-03-28 15:05, -5.43, 'red'], [2013-03-28 16:05, -5.12, 'red'], [2013-03-28 17:05, -5.42, 'red'], [2013-03-28 18:05, -5.16, 'red'], [2013-03-28 19:05, -5.11, 'red']]);
    chart.Set('chart.background.barcolor1', 'white');
    chart.Set('chart.grid.color', 'rgba(238,238,238,1)');
    chart.Set('chart.gutter.left', 30);
    chart.Set('chart.labels', ['12', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']);        
    chart.Set('chart.xmax', 12);
chart.Set('chart.line', true);
chart.Draw();
</script>

What am I missing?

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
TheEditor
  • 486
  • 1
  • 4
  • 18

2 Answers2

0

You don't have it in the correct format - there should be quotes around your date and the date itself isn't in the correct format. From memory it should be like this:

['2013/03/28 00:05:00', 0.00, 'red']

ie Quotes around the date (it's a string) and the date itself in a format that's understandable by Date.parse()

Richard
  • 4,809
  • 3
  • 27
  • 46
0

I agree with Richard. you need to quote the data you put in the Javascript. But don't try to escape it yourself, you will get an headache.

Since you are using PHP, just display the data you want with

echo json_encode($var);

It will handle it nicely if it is an array, a string, etc.

If it is an array of number, i suggest you use

echo json_encode($var,JSON_NUMERIC_CHECK);

This is very handy when you use RGraph with PHP.

Hope it helps.

Thibault
  • 1,566
  • 15
  • 22