X axis date scale


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by James Gardner on 1st March 2013
Hello,

I am using a javascript function for creating a date x-axis scale on a graph, however when using it recently it created the 29th, 30th and 31st February on the scale. Is there anything anyone could suggest?

thanks

ps here's the code that creates the scale:

<script>function xlabel(obj,num){var date = new Date(num); var day = date.getUTCDate(); var month = date.getUTCMonth(); var year = (date.getUTCFullYear() + '').substring(2,4); if(day<10){var day = '0' + day;} if(month<10){var month = '0' + month;} if(month==0){month = 12;} var formattedDate = day + '/' + month + '/' + year; return formattedDate}</script>

initiated by:

s.Set('chart.xscale.formatter', xlabel);
Posted by RGraph support on 1st March 2013
Hi there,

Obviously there's a bug in that function somewhere. I'd would advise you to either look around on the Internet for a function that does what you want or perhaps post on StackOverflow.

Though I would first suggest that you at least format the function to make it easier for people to read.


Richard, RGraph Support

1 Year Priority Support now reduced to £299:
   www.rgraph.net/support
Posted by James Gardner on 1st March 2013
Hi Richard,

I don't think the error is in that function, I think it's actually in the scale ie xmax and xmin. The two limits are dates but the fill in between includes up to 31st of Feb which is incorrect.

Cheers

James
Posted by RGraph support on 2nd March 2013
Hi there,

When passing dates as xmax/xmin/X values - they're simply converted to numbers with the Javascript Date object - which does accept the 31st February as a valid date.

Richard, RGraph support
RGraph - HTML5 and Javascript charts
www.rgraph.net
Posted by James Gardner on 3rd March 2013
Thanks. Is there a better way to create an X-Axis with correct dates in RGraph?

James
Posted by RGraph support on 3rd March 2013
Hi there,

Well the dates used as labels are simply text labels that you supply - so you'll need to add code to your function that generates the dates. As long as the correct xmax is set then the scale will be correct.


Richard, RGraph Support

1 Year Priority Support now reduced to £299:
   www.rgraph.net/support
Posted by James Gardner on 6th March 2013
The labels are not the problem, it's the scale that they are being written to.

I am setting xmin and xmax using php and Javascript and it works fine for dates within the same month, but with dates that cross months with less than 31 days, eg Feb, it includes 29, 30 and 31st of Feb in the scale, which is clearly wrong and throws off the graph.

Here is the code:

s.Set('chart.xmin', Date.UTC(<?php echo $startyear.",".$startmonth.",".$startday.",".$starthour.",".$startminute; ?>));
         s.Set('chart.xmax', Date.UTC(<?php echo $finishyear.",".$finishmonth.",".$finishday.",".$finishhour.",".$finishminute; ?>));

Is there a different way to ensure invalid dates aren't included?
Posted by Enter your name... on 6th March 2013
Hi there,

The Date.parse() function produces the same result for both of these dates:

Date.parse('2013-02-29 06:00:00');
Date.parse('2013-03-01 06:00:00');

Plus there's no need to use the Date.UTC() function - you can just pass the date string:

obj.Set('chart.xmin','2013-02-01 00:00:00');


Richard, RGraph support
RGraph - HTML5 and Javascript charts
www.rgraph.net
Posted by James Gardner on 7th March 2013
Hi Richard,

Removing the Date.UTC() caused the graph to fail to draw.

With regards to the Date.parse(), I want the method to not include 2013-02-29 ie recognise it as an invalid date for the graph because the scale drawn has a big connecting line between 28th Feb and 1st March. I don't want those dates on the scale at all.

Thanks

James
Posted by RGraph support on 7th March 2013
Hi there,

I'm sorry - I simply don't understand what is you want - there's a demo of a Date/ime scale here:

dev.rgraph.net/demos/scatter03.html

If you want separate lines on your Scatter chart then you could use a null value to break the line up or separate datasets.


Richard, RGraph Support

1 Year Priority Support now reduced to £299:
   www.rgraph.net/support
Posted by James Gardner on 8th March 2013
Is there somewhere I can send a screenshot of what I mean?


James
Posted by RGraph support on 8th March 2013
Hi there,

Sure - send it to the support address: support@rgraph.net


Richard, RGraph Support

1 Year Priority Support now reduced to £299:
   www.rgraph.net/support

Add a reply

 




« Back to message list
RGraph on social media