Scatter chart API reference
- Example
- How to specify the Scatter chart data
- Using dates and times instead of numeric X values
- How to specify errorbars
- Using image-based tickmarks
- Adding a line connecting the tickmarks
- Showing the coordinates using the labelsAbove feature
- The coordinates properties
- Properties
- Methods
- Data properties that are used on the tickmarks
- How to make trendline/dual-color Line charts
- Events
Example
<script> tooltip = 'Result: <b>%{value_formatted}</b>' data1 = [ {x:'1st January', y:0,tooltip: tooltip}, {x:'5th April', y:5.56,tooltip: tooltip}, {x:'27th February',y:23,tooltip: tooltip}, {x:'4th April', y:46,tooltip: tooltip}, {x:'1st October', y:18,tooltip: tooltip}, {x:'28th September', y:43,tooltip: tooltip}, {x:'23rd August', y:50,tooltip: tooltip}, {x:'1st June', y:12,tooltip: tooltip}, {x:'1st March', y:32,tooltip: tooltip}, {x:'27th July', y:12,tooltip: tooltip}, {x:'23rd April', y:32,tooltip: tooltip}, {x:'1st January', y:50,tooltip: tooltip}, {x:'3rd November', y:23,tooltip: tooltip}, {x:'12th December', y:15,tooltip: tooltip}, {x:'4th May', y:41,tooltip: tooltip} ]; data2 = [ {x:'4th January', y:0, tooltip: tooltip, color: 'red'}, {x:'9th April', y:5.56, tooltip: tooltip, color: 'red'}, {x:'24th February', y:23, tooltip: tooltip, color: 'red' }, {x:'8th April', y:46, tooltip: tooltip, color: 'red'}, {x:'9th October', y:18, tooltip: tooltip, color: 'red' }, {x:'24th September', y:43, tooltip: tooltip, color: 'red'}, {x:'21st August', y:50, tooltip: tooltip, color: 'red' }, {x:'2nd June', y:12, tooltip: tooltip, color: 'red'}, {x:'19th March', y:32, tooltip: tooltip, color: 'red' }, {x:'25th July', y:12, tooltip: tooltip, color: 'red'}, {x:'24th April', y:32, tooltip: tooltip, color: 'red' }, {x:'9th January', y:50, tooltip: tooltip, color: 'red'}, {x:'16th November', y:23, tooltip: tooltip, color: 'red' }, {x:'14th December', y:15, tooltip: tooltip, color: 'red'}, {x:'8th May', y:41, tooltip: tooltip, color: 'red' } ]; scatter = new RGraph.SVG.Scatter({ id: 'chart-container', data: [data1, data2], options: { marginLeft: 100, yaxisScaleDecimals: 2, xaxisScaleMin: '1st January 00:00:00', xaxisScaleMax: '31st December 23:59:59', xaxisLabels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], tickmarksStyle: 'circle', tooltipsFormattedUnitsPost: 'kg', tooltipsCss: { backgroundColor: '#333', fontWeight: 'bold', fontSize: '14pt', opacity: 0.85 } } }).draw(); </script>
How to specify the Scatter chart data
The Scatter chart
is slightly different
from other charts because, whereas other charts (usually)
use an array
of information to specify values, the
Scatter chart
uses an array
of objects
. This should come quite naturally
though as each Scatter chart
point can have
several different properties (eg x
value, y
value, tooltip
, color
etc).
At its most basic it looks like this:
var data = [ {x:5,y:7}, {x:7,y:9}, {x:1,y:3} ];
That would define three points, each with x
and y
values. There are other
things that you can add to each object (or just one/two
etc) and they are:
-
type
(If not specified the default is thetickmarksStyle
property, possible types are listed here) -
color
(If not specified the default is thecolors
property (one color per dataset - not each individual point) ) or failing that - thecolorsDefault
property -
size
(If not specified the default is thetickmarksSize
property) -
opacity
(If not specified the default is 1 -
tooltip
(If not specified, no tooltip will be present for this tickmark)
Another example where each point has all of the options specified is:
var data = [ {x:5,y:7,type: 'triangle',color: 'green', size: 10,opacity: 0.75,tooltip: 'The first tickmark'}, {x:7,y:9,type: 'square',color: 'red', size: 15,opacity: 0.5,tooltip: 'The second tickmark'}, {x:1,y:3,type: 'cross',color: 'cyan', size: 15,opacity: 0.25,tooltip: 'The third tickmark'} ];
Using dates and times instead of numeric x-axis
values
Instead of numeric x-axis
values, you can instead give a DateTime
string that
RGraph will parse (using the RGraph.SVG.parseDate
function) and use as
the value instead. The xaxisScaleMin
and xaxisScaleMax
values can also be specified
like this. The format of the DateTime
string can be varied (as you can
see from the example below). Here's an example of a DateTime
chart.
<script> data = [ {x:'23:59 15-01-2012', y:5}, {x:'2012 15th February', y:6}, {x:'Mar 15 2012', y:6}, {x:'2012/04/15', y:6}, {x:'2012-05.15', y:5}, {x:'2012 June 15', y:4}, {x:'July 2012 15th', y:5}, {x:'Aug 15th 2012', y:6}, {x:'15th September 2012', y:7}, {x:'15 Oct 2012', y:6}, {x:'2012.11.15', y:4}, {x:'2012.12-15 00:00:00', y:5} ]; new RGraph.SVG.Scatter({ id: 'chart-container', data: data, options: { backgroundGridVlines: false, backgroundGridBorder: false, yaxis: false, colors: ['red'], title: 'A Scatter chart using DateTime values', xaxisScaleMin: '2012/01/06 12:14:12', xaxisScaleMax: '31st dec 2012' } }).draw(); </script>
How to specify errorbars
You can specify errorbars on your Scatter chart
by using the errorbar
option in
the data array. The value can be either a simple number or an object which allows you a little
extra control. The example code below can be seen in a demo file in
the download archive named svg-scatter-errorbars.html
.
<script> var data1 = [ {x:1, y:7, errorbar: 3, color: 'red'}, {x:2, y:5, errorbar: {max: 6, color: 'red', linewidth: 2}, color: 'red'}, {x:3, y:3, errorbar: {min: 1, max: 1}, color: 'red'} ]; var data = [ {x:7, y:7, errorbar: {min: 1, max: null}, color: 'red'}, {x:8, y:5, errorbar: {min: 1, max: 1}, color: 'red'}, {x:10, y:3, errorbar: {min: 1, max: 1}, color: 'red'} ]; new RGraph.SVG.Scatter({ id: 'chart-container', data: [data, data1], options: { //errorbarsLinewidth: 5, //errorbarsCapwidth: 20, //errorbarsColor: 'pink', marginLeft: 35, xaxisScaleMin: 0, xaxisScaleMax: 12, xaxisLabels: ['Q1', 'Q2','Q3','Q4'], tickmarksStyle: 'circle' } }).draw(); </script>
Using image-based tickmarks
If the list of tickmarks does not suit your needs you can use an image as your tickmark instead. You can specify one by doing this:
<script> new RGraph.SVG.Scatter({ id: 'image-based-tickmarks', data: [ {x: 50, y: 26, type:'image:/images/a.png'}, {x: 100, y: 26, type:'image:/images/b.png'}, {x: 150, y: 26, type:'image:/images/c.png'}, {x: 200, y: 26, type:'image:/images/d.png'}, {x: 250, y: 26, type:'image:/images/e.png'} ], options: { title: 'A Scatter chart using image-based tickmarks', xaxisScaleMin: 0, xaxisScaleMax: 365, xaxisLabels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] } }).draw(); </script>
Adding a line connecting the tickmarks
By using the line
option you can have a line connecting the points,
therefore, creating a Line chart
- but with this Line chart
(instead of
the regular Line chart
) the points are not necessarily a fixed width apart - the x-axis
value
is totally down to you along with the y-axis
value. The DateTime
chart above
is also showing an example of using the line option.
With a little configuration, you can use the Scatter chart
with this
line option to show a Vertical Line chart
instead of a horizontal one.
There's an example that shows you an example of it in
the download archive.
Showing the coordinates using the labelsAbove feature
The Scatter chart
has the labelsAbove
feature - just like the Bar, Line and
Waterfall charts
. It's enabled a little differently though. Instead of
setting the labelsAbove
property to true you set the above
property in each points configuration object in the data to true. Like this:
<script> var data = [ {x:0, y:0, above:true}, {x:100, y:5, above:true}, {x:84, y:23, above:true}, {x:65, y:46, above:true}, {x:221, y:18, above:true} ]; new RGraph.SVG.Scatter({ id: 'chart-container', data: data, options: { xaxisScaleMax: 365, xaxisLabels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] } }).draw(); </script>
You can then use
the labelsAbove
configuration properties
that are shown below to
configure their appearance as normal.
The coordinates properties
The coordinates of all of the marks that are on the Scatter chart
are held
in the obj.coords
and obj.coords2
arrays. The difference between
the two is how they're indexed - the obj.coords
array is simply a
sequential array where each points information is simply appended to the
array. The obj.coords2
array on the other hand is indexed by dataset
and then by the index in that dataset. So if you have two datasets each
having six points then the obj.coords
array would look like
this:
obj.coords[0]
obj.coords[1]
obj.coords[2]
obj.coords[3]
obj.coords[4]
obj.coords[5]
obj.coords[6]
obj.coords[7]
obj.coords[8]
obj.coords[9]
obj.coords[10]
obj.coords[12]
obj.coords2
array would look like this:
obj.coords2[0][0]
obj.coords2[0][1]
obj.coords2[0][2]
obj.coords2[0][3]
obj.coords2[0][4]
obj.coords2[0][5]
obj.coords2[1][0]
obj.coords2[1][1]
obj.coords2[1][2]
obj.coords2[1][3]
obj.coords2[1][4]
obj.coords2[1][5]
element
The tickmarksvg
elementobject
TheScatter chart
objecttype
A string that denotes the type of the tickmark (eg cross)x
Thex-axis
coordinatey
They-axis
coordinatez
TheZ-axis
coordinate (commonly this is the size of the tickmark)
Properties
You can use these properties to control how the chart appears. You can set them by including them in the options section of the configuration as shown above.
- Background properties
- Margin properties
- Tickmark properties
- X-axis properties
- Y-axis properties
- Other text properties
- Line properties
- Key properties
- Tooltip properties
- Title properties
- Bubble chart properties
- Error bar properties
- Trend line properties
- Miscellaneous properties
Color properties
Background properties
svg
image tag, eg it could be XMinYMin meet
.x
coordinate of the image.y
coordinate of the image.linewidth
that the background grid lines are. Decimals (eg 0.5) are permitted.linedash
setting should be. It should be an array consisting of two numbers.linewidth
of the border that goes around the chart area.Margin properties
Tickmark properties
type
attribute in the data set (see above). Possible types are: cross
image:xxx
triangle
plus
square
(orrect
)circle
(ordot
)
X-axis properties
x-axis
labels.x-axis
labels.x-axis
scale.xaxisScaleMax
value that you set.x-axis
scale then you need to set this to control the maximum value that can be plotted on the chart.x-axis
scale.x-axis
scale.x-axis
scale.x-axis
scale.x-axis
scale.x-axis
scale - this should be a function that's passed two arguments - the object and the number - and should return the number formatted the way you wish. xaxisFormatter: function (obj, num) { return num; }
x-axis
title.x-axis
title.x-axis
title is bold or not.x-axis
title is italic or not.x-axis
coordinate of the x-axis
title.y-axis
coordinate of the x-axis
title.x-axis
title.Y-axis properties
y-axis
is positioned on the left or the right.yaxisScale
option is false then this can be used to give an array of labels that are shown on the y-axis
instead.y-axis
labels.y-axis
labels.y-axis
scale value. As well as a numeric value you can also set this to mirror
so that the x-axis
is put in the center.y-axis
. Units are not added, decimals are not added - it's all up to you. The function is passed two arguments - the chart object and the number. It should look like this: yaxisFormatter: function (obj, num) { }
y-axis
title.y-axis
title.y-axis
title is bold or not.y-axis
title is italic or not.x-axis
coordinate of the y-axis
title.y-axis
coordinate of the y-axis
title.y-axis
title.Other text properties
Scatter chart
labelsAbove
isn't enabled by using this property - it's enabled by using the "above" parameter within each points configuration object in the data (the place where you specify the x-axis
and y-axis
values).labelsAbove
labels (this is for the X coordinate).labelsAbove
labels (this is for the X coordinate).labelsAbove
labels (this is for the x-axis
coordinate).x-axis
coordinate.labelsAbove
labels (this is for the x-axis
coordinate).labelsAbove
labels (this is for the x-axis
coordinate).x-axis
coordinate.labelsAbove
labels (this is for the y-axis
coordinate).labelsAbove
labels (this is for the y-axis
coordinate).labelsAbove
labels (this is for the y-axis
coordinate).y-axis
coordinate.labelsAbove
labels (this is for the y-axis
coordinate).labelsAbove
labels (this is for the y-axis
coordinate).y-axis
coordinate.labelsAbove
labels.Line properties
Key properties
colors
option will be used instead.textFont
setting.textSize
is used.Tooltip properties
Scatter chart
is given as part of the data that you give in the initial configuration when you create the chart. You can also check the canvas tooltips documentation for more information.tooltipsOverride: function (obj, opt)
{
// Show tooltip
}
The opt is an argument that contains these items: object
The chart object.index
The index of the element (that triggered the tooltip).sequentialIndex
The sequential index of the element that was clicked.text
The text to be used as the tooltip. Remember that this may containhtml
(or whatever else you may have specified).event
The event object (either aclick
ormousemove
event).
click
or mousemove
.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.square
or circle
css
values to the key color shape that appears in the tooltip key. Note the property name is "color" and not "colors" like previous properties. It should be an object of css
properties like this: tooltipsFormattedKeyColorsCss : { border: "1px solid #ddd"; }
ul
and ol
.tooltipsFormattedListItems: [ ['Bill','Jerry','Berty'], // First tooltip ['Gill','Carrie','Lucy'], // Second tooltip ['Pob','Nobby','Hilda'] // Third tooltip ]You can use
css
to style this list - for example:.RGraph_tooltip ul#rgraph_formatted_tooltips_list li { text-align: left; color: yellow; }
th
tags.canvas
documentation, copy the code from it and then modify it suit. You'll create fewer bugs this way.css
values applied to the tooltips pointer (a css
border, for example) then specify an object containing those values to this property. For example: tooltips: { borderLeft: 'gray 2px solid', borderBottom: 'gray 2px solid' }
false
tooltips are positioned next to the mouse pointer.css
that gets applied to all of the tooltips, but don't want to use the RGraph.SVG.tooltips.style
object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object css
for the tooltips. These are css
styles that get applied to all of the tooltips for the specific object only. It should look like this:tooltipsCss: { fontFamily: 'Verdana', fontSize: '20pt' }
css
class that's applied to the tooltip div
.Title properties
x-axis
coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.y-axis
coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.x-axis
coordinate.y-axis
coordinate.marginTop
value.Bubble chart properties
Scatter chart
should be drawn as a Bubble chart
. As well as x-axis
and y-axis
coordinates, Bubble charts
also require a Z coordinate. You can see an example of a Bubble chart
in the download archive.Error bar properties
Scatter charts
the errorbar information is supplied in each points object within the data array.errorbars
. This can be overridden using the color
setting if you give an object as the errorbar
property in the data array.Trend line properties
linewidth
of the trend line(s). It can be a single number or an array of numbers if you have multiple datasets.Miscellaneous properties
y-axis
minimum and/or maximum values set but still want to show values that fall outside these bounds then you can set this property to true.- value: The value you want the line positioned at or the keyword average (default: average)
- color: The color of the line (default: #666)
- dashed: Whether the line is dashed or not (default: true)
- dotted: Whether the line is dotted or not (default: false)
- linewidth: The
linewidth
of the line (default: 1) - label: this is The label that appears above (by default) the line. If you don't want a label you can set this to an empty string. default: Average (%{value})
- labelPosition: This can be a string that consists of the following keywords: left/center/right top/bottom (default: top right)
- labelFont: The font that the label is drawn in (default: [the same as the textFont property])
- labelColor: The color that the label is drawn in (default: #666)
- labelSize: The size of the label (in points) (default: 4 points less than the textSize setting)
- labelBold: Whether the label is bold or not (default: null [falls back to the textBold setting])
- labelItalic: Whether the label is italic or not (default: null [falls back to the textItalic setting])
- labelValueDecimals: How many decimals are shown on the number. (default: 2)
- labelValuePoint: The character used as the decimal point. (default: .)
- labelValueThousand: The character used as the thousand separator charactor.(default: ,)
- labelValueUnitsPre: This string is prended to the number. (default: [an empty string])
- labelValueUnitsPost: This string is appended to the number. (default: [an empty string])
- labelOffsetx: The horizontal offset that's applied to the X coordinate. (default: 0)
- labelOffsety: The vertical offset that's applied to the Y coordinate. (default: 0)
- labelValueFormatter: This function handles ALL of the formatting of the number. (default: null)
obj.set('horizontalLines', [ { value: 'average', dashed: true, labelPosition:'left bottom' }, { value: 10.48, label:'Value (%{value})', labelValueDecimals: 2, labelValueThousand: ',', labelValuePoint:'.', labelValueUnitsPre:'', labelValueUnitsPost:'' //labelValueFormatter: function (opt) //{ // return opt.number; //} } ]);
Methods
obj.get(name)
This can be used to get properties if necessary. It's normally used after the chart is drawn if you need to get parameters (if you're doing custom coding for example).
obj.set(name, value)
This can be used to set properties if necessary. It's normally used after the chart is drawn if you need to set additional parameters or change them.
obj.getXCoord(value)
This method can be used to get an appropriate x-axis
coordinate for a value when you're
doing custom drawing on the chart. It returns null
if the value is out of
range.
obj.getYCoord(value)
This method can be used to get an appropriate y-axis
coordinate for a value when you're
doing custom drawing on the chart. It returns null
if the value is out of
range.
obj.on(event, handler)
This function adds an event listener (such as beforedraw
or
draw
) to the chart object. For example:
obj.on('draw', function (obj)
{
// Put your code here
});
obj.exec(func)
This function can be used to execute a function (immediately). It's not event-based
(ie it doesn't run when something happens) - it just runs immediately - and only once.
You might use it when you need to get something from the chart when it's drawn and
then call the redraw function. Because this function only runs once the RGraph.SVG.redraw
function would not cause a loop - which would happen if you used the draw
event.
obj.exec(function (obj)
{
// Put your code here
});
obj.responsive(configuration)
The responsive
function helps your charts
respond to different browser window sizes and screen
resolutions. For example, for smaller screens, you
might want to have angled labels or show shorter
versions of them completely.
Update: There is now the responsive configuration option available to you and this is now the preferred method of configuration.
The responsive function and configuration option are documented on their own page here.
Data properties that are used on the tickmarks
The svg
elements that represent the tickmarks (eg path
,
circle
elements) on the Scatter chart
have
various data attributes added to them that hold various bits of information. These
are:
- data-index
- data-dataset
- data-original-opacity
- data-original-color
- data-original-coordx
- data-original-coordy
- data-size
- data-sequential
- data-type
These can be retrieved by using standard dom
methods:
obj.coords[0].element.getAttribute('data-index');
How to make trendline/dual-color Scatter charts
This type of chart has been made far easier thanks to
the clip
property which was introduced in version 6.17
It was perfectly possible before this feature was
introduced - it's just been made easier. Also, it's made
easy to implement because all of the necessary
configuration is hidden away in a new function which
does the hard parts for you. Here's some example code
for the svg
Scatter chart
.
You can see this code in the download archive in a demo
called svg-scatter-trendline-dual-color.html
<script> // Data for the Scatter chart (lots of it) data = [ {x:6347.82,y:0.69}, {x:8956,y:0.51}, {x:5620,y:0.34}, {x:8092,y:0.34}, {x:5069,y:0.8}, {x:5924,y:0.05}, {x:7851,y:0.2}, {x:2065,y:0.72}, {x:3872,y:0.29}, {x:6521.73,y:0.50}, {x:28501,y:0.37}, {x:18344,y:0.37}, {x:26561,y:0.39}, {x:21391.30,y:0.33},{x:24628,y:0.4}, {x:24670,y:0.46}, {x:15689,y:0.76}, {x:8000,y:0.70}, {x:23921,y:0.43}, {x:30434.78,y:0.56},{x:18809,y:0.96}, {x:24695.65,y:0.18},{x:16000,y:0.33}, {x:27445,y:0.59}, {x:11926,y:0.21}, {x:16819,y:0.78}, {x:21739.13,y:0.69},{x:8956.52,y:0.74}, {x:28059,y:0.61}, {x:20458,y:0.19}, {x:23079,y:0.2}, {x:20762,y:0.48}, {x:17547,y:0.54}, {x:28706,y:0.72}, {x:22361,y:0.48}, {x:8956.52,y:0.79}, {x:21696,y:0.59}, {x:17026,y:0.65}, {x:12766,y:0.67}, {x:22618,y:0.5}, {x:23902,y:0.59}, {x:24539,y:0.54}, {x:23700,y:0.6}, {x:22334,y:0.29}, {x:24830,y:0.66}, {x:10086.95,y:0.39},{x:12263,y:0.4}, {x:26057,y:0.22}, {x:28744,y:0.94}, {x:12151,y:0.16}, {x:22528,y:0.37}, {x:18521.73,y:0.22},{x:32173.91,y:0.36}, {x:29355,y:0.87}, {x:17036,y:0.52}, {x:32000,y:0.44}, {x:24312,y:0.58}, {x:29227,y:0.71}, {x:24173,y:0.29}, {x:18070,y:0.66}, {x:13321,y:0.34}, {x:25660,y:0.47}, {x:23860,y:0.26}, {x:17391.30,y:0.16},{x:25217.39,y:0.74}, {x:20115,y:0.53}, {x:18988,y:0.19}, {x:28591,y:0.68}, {x:8956.52,y:0.26}, {x:26695.65,y:0.78},{x:13234,y:0.18}, {x:20197,y:0.73}, {x:20187,y:0.77}, {x:20888,y:0.29}, {x:21652.17,y:0.22},{x:29348,y:0.77}, {x:14869.56,y:0.63}, {x:10909,y:0.55}, {x:18173.91,y:0.30},{x:12372,y:0.5}, {x:24173.91,y:0.8}, {x:28173.91,y:0.28},{x:16521,y:0.22}, {x:16905,y:0.87}, {x:24099,y:0.36}, {x:15210,y:0.18}, {x:24069,y:0.44}, {x:15062,y:0.49}, {x:22162,y:0.17}, {x:30521.73,y:0.37},{x:24838,y:0.42}, {x:19236,y:0.2}, {x:12402,y:0.51}, {x:29949,y:0.88}, {x:24314,y:0.3}, {x:29584,y:0.84}, {x:21705,y:0.6}, {x:11651,y:0.32}, {x:15174,y:0.85}, {x:26007,y:0.92}, {x:26603,y:0.22}, {x:21484,y:0.87}, {x:24855,y:0.37}, {x:15524,y:0.91}, {x:16521.73,y:0.37}, {x:28304,y:0.82}, {x:17427,y:0.45}, {x:27818,y:0.81}, {x:17215,y:0.75}, {x:11935,y:0.79}, {x:12761,y:0.51}, {x:11185,y:0.31}, {x:12103,y:0.62}, {x:17421,y:0.63}, {x:21176,y:0.77}, {x:17941,y:0.4}, {x:18080,y:0.84}, {x:32173.91,y:0.51},{x:22556,y:0.85}, {x:22592,y:0.24}, {x:29128,y:0.79}, {x:32260.86,y:0.76},{x:26192,y:0.28}, {x:22912,y:0.34}, {x:18429,y:0.54}, {x:23469,y:0.36}, {x:19356,y:0.38}, {x:15321,y:0.43}, {x:23020,y:0.73}, {x:17212,y:0.23}, {x:28172,y:0.49}, {x:24610,y:0.26}, {x:28472,y:0.59}, {x:19744,y:0.66}, {x:15460,y:0.5}, {x:28877,y:0.37}, {x:29870,y:0.39}, {x:23475,y:0.47}, {x:25629,y:0.7}, {x:10521.73,y:0.14},{x:27358,y:0.75}, {x:28036,y:0.97}, {x:19552,y:0.86}, {x:25319,y:0.6}, {x:29466,y:0.95}, {x:18861,y:0.88}, {x:29852,y:0.88}, {x:28877,y:0.89}, {x:27523,y:0.56}, {x:13435,y:0.12}, {x:29399,y:0.58}, {x:21698,y:0.9}, {x:14347.82,y:0.26}, {x:28909,y:0.36}, {x:20870,y:0.25}, {x:26751,y:0.76}, {x:24434.78,y:0.87}, {x:12079,y:0.15}, {x:16765,y:0.1}, {x:11674,y:0.6}, {x:11058,y:0.78}, {x:11844,y:0.3}, {x:14777,y:0.36}, {x:20823,y:0.91}, {x:15992,y:0.23}, {x:26171,y:0.85}, {x:19652.17,y:0.11},{x:22841,y:0.62}, {x:21527,y:0.52}, {x:27084,y:0.32}, {x:28173.91,y:0.87},{x:20249,y:0.95}, {x:12818,y:0.24}, {x:13924,y:0.14}, {x:22007,y:0.4}, {x:12560,y:0.71}, {x:17194,y:0.75}, {x:14173.91,y:0.70},{x:11808,y:0.34}, {x:29015,y:0.82}, {x:10000,y:0.23}, {x:23854,y:0.76}, {x:10260.86,y:0.65},{x:25037,y:0.29}, {x:17254,y:0.25}, {x:20473,y:0.85}, {x:23831,y:0.3}, {x:19478.26,y:0.28},{x:15871,y:0.81}, {x:21073,y:0.15}, {x:8869.56,y:0.16}, {x:13192,y:0.8}, {x:24882,y:0.56}, {x:27202,y:0.68}, {x:24327,y:0.29}, {x:7826.08,y:0.63}, {x:29565.21,y:0.473}, {x:17058,y:0.82}, {x:19212,y:0.53}, {x:16224,y:0.6}, {x:11975,y:0.85}, {x:18575,y:0.8}, {x:26226,y:0.58}, {x:17591,y:0.1}, {x:23667,y:0.63}, {x:18782.60,y:0.14},{x:16372,y:0.77}, {x:30173.91,y:0.26},{x:21435,y:0.84}, {x:25027,y:0.31}, {x:36356,y:0.5}, {x:36284,y:0.53}, {x:44203,y:0.76}, {x:44869.56,y:0.86},{x:33485,y:0.73}, {x:38798,y:0.75}, {x:34666,y:0.85}, {x:39210,y:0.63}, {x:45565.21,y:0.63},{x:42947,y:0.91} ]; // Configuration options that are given to both Scatter charts options = { marginTop: 50, marginBottom: 60, marginRight: 60, marginLeft: 60, textSize: 16, xaxisLabels: ['0','10,000','20,000','30,000','40,000','50,000'], xaxisLabelsPosition: 'edge', xaxisLabelsPositionEdgeTickmarksCount: 6, xaxisScaleMax: 50000, yaxisScaleDecimals: 1, xaxisColor: '#333', backgroundGridColor: '#eee', backgroundGridVlines: false, backgroundGridBorder: false, trendline: true, trendlineColors: ['gray'], trendlineLinewidth: 2, trendlineDashArray: [5,10], tickmarksStyle: 'dot', tickmarksSize: 5 }; // // This is all the code that's necessary to produce the // dual-color Scatter chart // [scatter1, scatter2] = RGraph.SVG.Scatter.dualColorTrendline({ id: 'chart-container', data: data, options: options, // The configuration options for both of the charts optionsTop: {colors: ['black']}, // Configuration options for just the top chart optionsBottom: {colors: ['red']}, // Configuration options for just the bottom chart animationEffect: 'trace', // The animation effect to use (for both charts) animationEffectOptions: {frames: 120}, // Any options to give to the animation effect animationEffectCallback: function () {alert('Finished!');} // Any options to give to the animation effect }); </script>
Events
RGraph supports custom events that allow you to easily add interactivity to your charts if required. The following events are available:
beforedraw
This event fires at the start of thedraw
method before anything has been done.draw
This event fires at the end of thedraw
function.firstdraw
This event fires at the end of thedraw
function - but only the first time and so it fires only once after the firstdraw
call.beforetooltip
This event fires at the start of the tooltip showing process.tooltip
This event fires after a tooltip has been shown.
new RGraph.SVG.Scatter({ id: 'chart-container', data: [ {x:355, y:18, color: 'red'}, {x: 25, y:35, color: 'red'}, {x:120, y:23, color: 'red' }, {x: 65, y:46, color: 'red'}, ], options: { xaxisScaleMax: 365 } }).on('tooltip', function (obj) { console.log('The draw event has fired'); }).draw();