RGraph is a JavaScript charts library based on
HTML5 SVG and canvas. RGraph is mature (over 17 years
old) and has a wealth of features making it an ideal
choice to use for showing charts on your website.
Get the latest version of RGraph (version 6.20, 1st December 2024) from
the download page. You can read the changelog here. There's also older versions available,
minified files and links to cdnjs.com hosted libraries.
Can I show three (or more) colors on my Line chart?
Posted by giuseppe at 13:29 on Wednesday 23rd March 2022[link]
hi
I'm using successfully RGraph.line.js and related libraries.
I made a dual-color line graph but now i'd need to add a color, so graph should be a three colors.
Is it possible or exist a new better way ?
many thanks
Posted by Richard at 18:12 on Wednesday 23rd March 2022[link]
You can. You can do it in two ways that I can think of:
1. Use gradients. There are two demo pages in the download archive that show this:
i. line-filled-striped.html
ii. line-banded-gradient.html
2. Use clipping. This is a little more involved and involves drawing a path (a rectangle in your case by the sounds of it) to which any further drawing is restricted.
So you set the clipping, draw the first chart, reset the clipping.
Set new clipping (to the second section), change the colors on the chart and then draw it again, then reset the clipping.
And finally set new clipping to the third section, change the colors again and draw the chart. Then reset the clipping.
This, as you can see, is more involved but it is a bit more versatile.
I'm actually in the middle of creating an RGraph.clipTo.start() function which will make this much easier - so if you hold on a few days I'll send you an updated RGraph.common.core.js file so you can use it.
Posted by Richard at 20:58 on Thursday 24th March 2022[link]
Ok, try having a look at this example:
[LINK REMOVED]
To use this sort of chart on your own website you'll need to use this version of the core library:
[LINK REMOVED]
And you can get the source of the example page by viewing the source in your browser.
UPDATE
This is now part of version 6.07 and you can read about the RGraph.clipTo functions in the API documentation: