How do I get keys to work with my SVG Line chart?

« 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 Ian on 17th January 2018

So, I'm completely new to RGraph, and JS in general, but I'm implementing a statistics function for an app at work.

I've gotten the graphs to work and display data from the database, but I'm having trouble with something that I intuitively thought would be basic stuff... keys.

All I want is to add a legend to my graphs. It seems the only way to do this is through keys (but I very well may be wrong). I'm using the SVG.Line and SVG.common.core libraries to draw the graph, and the common.key for the keys, but when I add the "key"-variable to options, I get a javascript alert that prompts me to include the key library.

I'm completely baffled. I thought the keys were just part of another object or function in the svg.line library (the various key-related variables exist there, anyway), and would work in the same way that, say, xaxisLabels works (i.e. just include the key-names correlating to the amount of lines).

The only thing I'm really trying to accomplish is adding the ability to distinguish between sets of data.

Thanks in advance!
- Ian
Posted by Richard on 17th January 2018
Hi there,

> So, I'm completely new to RGraph, and JS in general, but I'm implementing a statistics function for an app at work.

So I'm guessing there's no web guy where you work and you got lumbered with it? :-)

Have you included the key library file in your page? Doesn't sound like you have if you're seeing that message. Add this to your page:

<script src="RGraph.svg.common.keys.js"></script>

I've made you an example of a Line chart with a key here:

Posted by Ian on 18th January 2018
First off, thanks so much for the quick response - and an example to boot!

Second, nah. This wasn't so much lumbered on me as, well, me taking the initiative to implement an idea that I had. There are some skilled programmers here, but this one baffled theem as well. That makes sense, too - because it was such an inconspicuous bug (as bugs often are) that it missed us.

It turns out I was including the RGraph.common.key.js script, which was incorrect for the graph (but inspecting the page revealed that the browser got an http 200 when getting the library - which at that moment was very confusing). The correct key library for the svg functions is called RGraph.svg.common.key.js (as per what you showed in the example). So, once again, I learn that errors are rarely... mistaken.

Anyway, it works perfectly now. Thanks again lots for your help!
- Ian

Add a reply

« Back to message list