How do you change the labels set for a Line chart?

Share RGraph:   To help my Google visibility (it can't get much worse!), if you like and use RGraph I'd appreciate it if you could link to me

« 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 Mike McPherson on 15th December 2013
I have a nice line chart with x labels of months
I want to be able to change this to days fo the week for example
I have to arrays months and days
I tried
MyGraph.Set('labels', days) .Draw();

but it fails and my code stops dead in its tracks!

er - help!

thanks
Mike
Posted by RGraph support on 15th December 2013
Hi there,

Probably the easiest way would be to have two separate functions - both of which first reset the canvas and then draw the chart. There's an example of the method here (no charts though - just code structure):

www.rgraph.net/fiddle/view/a-line-chart-that-switches-from-months-to-weeks

Then simply have two buttons which call those functions, like this:

<button onclick="drawMonthly()">Monthly chart</button>
<button onclick="drawYearly()">Yearly chart</button>


The concept is shown here:

www.rgraph.net/docs/howto-make-a-transition-effect.html





Richard, RGraph Support
www.rgraph.net
Please link to the RGraph website. Thanks!
Posted by Mike McPherson on 16th December 2013
I also tried
temperature.labels = days;
RGraph.Redraw();

doesn't crash the code now
but still doesn't display new labels :(
Posted by Mike McPherson on 16th December 2013
hmm
I tried
RGraph.Clear(document.getElementById('tempCanvas'));
but it did nothing
but
RGraph.Reset(document.getElementById('tempCanvas'));
did clear the canvas

then created a new Line

is this the correct way to do it?
cheers
Mike
Posted by RGraph support on 16th December 2013
Hi there,

The Clear function just clears the canvas - whereas the Reset function tries to "forget" the chart so that you can start over again.



Richard, RGraph Support
www.rgraph.net
Please link to the RGraph website. Thanks!
Posted by Mike McPherson on 16th December 2013
aha
saw your replies just after I posted mine
all working now
thanks!

PS I linked the site that uses Rgraph back to yours :)
www.mmcpix.com/wxgraphs.html
guages are live data, graphs are still test data,
but now I can drive the bits I need...
Posted by RGraph support on 16th December 2013
Hi there,

Great. It may be a bit easier to read if you give the canvas a white background:

<canvas width="400" height="200" id="cvs" style="background-color: white; border: 1px solid gray"></canvas>



Richard, RGraph Support
www.rgraph.net
Please link to the RGraph website. Thanks!
Posted by Mike McPherson on 16th December 2013
excellent
and thanks for your help
showing real data now
just need a few tweaks!

Add a reply




« Back to message list