The drawing API Image object API reference
The image object allows you to add images to your charts. The image can,
for example, be
used as a way to provide an extra tooltip
to your users or it can be used as a background image
instead of using the built-in backgroundImage
option.
The advantage, in this case, is that by
using the image drawing object as the background image instead of specifying
a background image for the Line chart
(which you can do with the backgroundImage
option) is that you
can click the background and have the
click
event triggered or show a tooltip.
Usage example
<script>
new RGraph.Line({
id: 'cvs',
data: [4,9,1,3,2,6,5],
options: {
xaxisLabels: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
marginInner: 5,
tickmarksStyle: 'endcircle',
colors: ['black'],
tooltips: ['A','B','C','D','E','F','G'],
marginBottom: 35,
textSize: 10
}
}).draw();
image = new RGraph.Drawing.Image({
id: 'cvs',
x: 40,
y: 40,
src: '/images/logo.png', // CHANGE THIS TO AN IMAGE ON YOUR WEBSITE
options: {
width: 32,
height: 32,
tooltips: ['Your logo!'],
textSize: 10
}
}).draw();
</script>
Properties
- Configuration properties
- Background properties
- Color properties
- Shadow properties
- Interactive features properties
- Border properties
- Labels and text properties
- Miscellaneous properties
Configuration properties
Background properties
Color properties
Shadow properties
Interactive features properties
obj.set('tooltips', ['The tooltip'])
.click
or mousemove
and controls what event is used to trigger the tooltip.RGraph.clear
api
function the tooltip DOES NOT get hidden.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.%{value_formatted}
option.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.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.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' }
Border properties
Labels and text properties
dom
text in place of canvas
text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas
but to wrap the canvas
in a div
and set them on that like this:
<div style="margin-left: 50px; display: inline-block"> <canvas id="cvs" width="650" height="250"></canvas> </div>
Miscellaneous properties
null
but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument.Methods
obj.get(name)
An accessor that you can use to retrieve the values of properties.
obj.set(name, value)
An accessor that you can use to set the values of properties.
obj.getShape(event)
This method makes it easy to get hold of the image when it has been clicked on or hovered over. It returns an object which has the following indexes available:
object |
The chart object. |
x |
The X coordinate of the image. |
y |
The Y coordinate of the image. |
width |
The width of the image. |
height |
The height of the image. |
dataset |
As there's only ever one element this is always zero. |
index |
As there's only ever one element this is always zero. |
sequentialIndex |
As there's only ever one element this is always zero. |
tooltip |
If a tooltip is associated with the Background object this will be it.id:
strings are expanded for you (where the tooltip text is retrieved from the html
tag with the matching ID).
|
<script>
image.canvas.onclick = function (e)
{
RGraph.redraw();
var canvas = e.target,
obj = canvas.__object__,
shape = obj.getShape(e);
if (shape) {
// Highlight the main body of the Image object.
obj.path(
'lw 10 b r % % % % s black f rgba(255,0,0,0.25)',
shape.x, shape.y, shape.width, shape.height
);
}
}
</script>
obj.on(event, function)
This method can be used to set an event listener on an object.
It operates similarly to the jquery
on
function.
The first argument is the event that you wish to attach to and the second
is the handler function. For example:
obj.on('draw', function (obj)
{
// Put your event code here
});
The function is useful if you use method chaining when creating your charts:
var obj = new RGraph.Drawing.Image({ id: 'cvs', x: 64, y: 64, src: '/images/logo.png', }).on('draw', function (obj) { // Put your draw event code here }).on('click', function (e, shape) { // Handle the click event }).draw();
obj.exec(function)