Meter charts documentation

Recommend RGraph:  
    Read comments...

 

Example

<script>
    var meter = new RGraph.Meter({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 6.4,
        options: {
            colorsRanges: [
                [0,10, 'Gradient(white:red)'],
                [10,35, 'Gradient(white:yellow)'],
                [35,100, 'Gradient(white:green)']
            ]
        }
    }).draw();
</script>

The example file is here.

 

Properties

You can use these properties to control how the chart apears. You can set them by including them in the options section of the configuration as above.

 

Chart configuration

centerx
If required, you can position the Meter chart using this instead of the gutters.
Default: null

centery
If required, you can position the Meter chart using this instead of the gutters.
Default: null

radius
If required, you can size the Meter chart using this instead of the gutters.
Default: null

anglesStart
You can specify the angle that the Meter should start at with this property. Keep in mind though - that by default the Meter is positioned at the bottom of the canvas. Remember that there are three "constants" available for you to use: RGraph.HALFPI, RGraph.PI, RGraph.TWOPI
Default: Pi (3.14...)

anglesEnd
You can specify the angle that the Meter should end at with this property. Keep in mind though - that by default the Meter is positioned at the bottom of the canvas. Remember that there are three "constants" available for you to use: RGraph.HALFPI, RGraph.PI, RGraph.TWOPI
Default: 2 * Pi (6.28...)

 

Background

backgroundImageUrl
The URL of an image that is used as the background for the Meter. If you use a background image you can create some significantly different looking Meters. You can see examples in the demos.
Default: null

backgroundImageOffsetx
By default the image is positioned at [0,0] (the top left of the canvas) - you can use this to move the image left (negative) or right (positive).
Default: 0

backgroundImageOffsety
By default the image is positioned at [0,0] (the top left of the canvas) - you can use this to move the image up (negative) or down (positive).
Default: 0

backgroundImageStretch
If true (the default) then the image will be stretched to fit the canvas width and height (the width and height are the same as the canvas width and height).
Default: true

backgroundColor
The background color for the Meter. If you have a non-white background you may want to change this.
Default: white

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 25

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 25

 

Colors

strokestyle
The color of the bits separating the segements. By setting this to white you can get a separation effect.
Default: null

borderColor
The color of the outline (including tickmarks).
Default: black

greenStart
The value that the green area should begin at.
Default: 35% of the maximum value

greenEnd
The value that the green area should end at.
Default: The maximum value

greenColor
The color of the green area.
Default: #207A20

yellowStart
The value that the yellow area should begin at.
Default: 10% of the maximum value

yellowEnd
The value that the yellow area should end at.
Default: 35% of the maximum value

greenColor
The color of the yellow area, (can be any color).
Default: #D0AC41

redStart
The value that the red area should begin at.
Default: The minimum value

redEnd
The value that the red area should end at.
Default: 10% of the maximum value

redColor
The color of the red area, (can be any color).
Default: #9E1E1E

colorsRanges
If the green/yellow/red colors don't suit your desired Meter you can use this to completely control the color ranges on your chart. An example for a chart with a range of 0-100 would be:
obj.set('colors.ranges', [[0, 60, 'green'],[60, 80 'yellow'],[80, 100, 'red']]);

Default: null

 

Labels and text

textAccessible
A new feature in 2016 that allows you to use 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>

Default: true

textAccessibleOverflow
This can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small gutters if you wish.
Default: visible

textAccessiblePointerevents
This controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).
Default: true

textColor
The color of the labels.
Default: black

textSize
The size (in points) of the labels.
Default: 10

textFont
The font used to render the text.
Default: Arial

textValign
The vertcal alignment of the text. In some cases you may want to change this to bottom
Default: center

valueText
This option controls whether the value of the Meter is shown in text.
Default: false

valueTextDecimals
The amount of decimals shown in the text label.
Default: 0

valueTextUnitsPre
The units (before the value) shown in the text label.
Default: An empty string

valueTextUnitsPost
The units (after the value) shown in the text label.
Default: An empty string

labels
Whether the labels are shown or not.
Default: true

labelsCount
This is used to stipulate how many labels are drawn on the Meter.
Default: 10

 

Titles

title
The title of the chart, if any.
Default: null

titleFont
The font that the title is rendered in. If not specified the text.font setting is used (usually Arial)
Default: null

titleSize
The size of the title. If not specified the size is usually 2pt bigger than the text.size setting.
Default: null

titleBold
Whether the title is bold or not.
Default: true

titleItalic
Whether the title is italic or not.
Default: false

 

titleBackground
The background color (if any) for the title.
Default: null

titleColor
The color of the title.
Default: black

titleX
To give the exact X coordinate for the title - use this
Default: null

titleY
To give the exact Y coordinate for the title - use this
Default: null

 

Scale

unitsPre
The units that the labels are measured in. This string is displayed BEFORE the actual number, allowing you to specify values such as "$50".
Default: none

unitsPost
The units that the labels are measured in. This string is displayed AFTER the actual number, allowing you to specify values such as "50ms".
Default: none

scaleDecimals
The number of decimal places to display for the values.
Default: 0

scalePoint
The character used as the decimal point.
Default: .

scaleThousand
The character used as the thousand separator
Default: ,

 

Interactive features

contextmenu
An array of context menu items. More information on context menus is here.
Default: [] (An empty array)

resizable
Defaulting to false, this determines whether your chart will be resizable. Because of the numerous event handlers this has to install code on, This feature is unlikely to work with other dynamic features (the context menu is fine however).
Default: false

resizeHandleBackground
With this you can specify the background color for the resize handle. If you're adjusting the position of the handle then you may need this to make the handle stand out more.
Default: null

resizableMaxwidth
This allows you to set a maximum width that the chart can be resized to.
Default: null

resizableMaxheight
This allows you to set a maximum height that the chart can be resized to.
Default: null

annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false

annotateColor
If you do not allow the use of the palette, then this will be the only colour allowed for annotations.
Default: black

annotateLinewidth
This is the line width of the annotations.
Default: 1

adjustable
Defaulting to false, this determines whether your bar chart will be adjustable.
Default: false

 

Shadow

shadow
Whether a drop shadow is applied.
Default: false

shadowColor
The color of the shadow.
Default: rgba(0,0,0,0.5)

shadowOffsetx
The X offset of the shadow.
Default: 3

shadowOffsety
The Y offset of the shadow.
Default: 3

shadowBlur
The severity of the shadow blurring effect.
Default: 3

 

Zoom

zoomFactor
This is the factor that the chart will be zoomed by (bigger values means more zoom)
Default: 1.5

zoomFadeIn
Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomFadeOut
Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomHdir
The horizontal direction of the zoom. Possible values are: left, center, right
Default: right

zoomVdir
The vertical direction of the zoom. Possible values are: up, center, down
Default: down

zoomDelay
The delay (in milliseconds) between frames.
Default: 50

zoomFrames
The number of frames in the zoom animation.
Default: 10

zoomShadow
Whether or not the zoomed canvas has a shadow or not.
Default: true

 

Miscellaneous

linewidth
The width of the outline of the Meter.
Default: 2

linewidthSegments
The linewidth of the lines separating the segments.
Default: 1

tickmarksSmallNum
This controls the number of small tickmarks.
Default: 100

tickmarksBigNum
This controls the number of large tickmarks.
Default: 10

tickmarksSmallColor
This sets the color of the small tickmarks.
Default: #bbb

tickmarksBigColor
This sets the color of the large tickmarks.
Default: black

border
Whether the outline is drawn.
Default: true

segmentRadiusStart
Instead of the segments going from the center point outwards, you can use this to specify a start point of the coloured segments.
Default: null

needleRadius
This can be used to stipulate the radius of the pointer.
Default: null

needleLinewidth
This can be used to specify the linewidth used when drawing the needle.
Default: null

needleTail
If true the needle will have a small tail.
Default: false

needleColor
The color of the needle. You'll probably also want the centerpin properties too.
Default: black

needleImageUrl
If you want to use an image for the needle then you can using this property. Combined with the background image this can make some significantly different looking Meters. The needle should be pointing right (like this, or like this) Two examples of using the image properties are: one, two
Default: null

needleImageOffsetx
Needle images are drawn so that the top left of the needle image is the centerx/centery of the Meter chart (when the needle is horizontal and pointing to the right). You'll probably want to center your needle image and you can do so with these properties. Centering is best done when the needle is pointing right. So if you haven't changed the angles this will be when the Meters value is the maximum value. If you have changed the angles then you'll have to pick a suitable value so the needle is pointing right.
Default: 0

needleImageOffsety
As above but for the needles Y positioning.
Default: 0

centerpinStroke
The color of the stroke around the centerpin of the needle.
Default: black

centerpinFill
The color of the stroke around the centerpin of the needle.
Default: black

clearto
This is used in animations and effects as the default color to use when the canvas.
Default: null

 

Methods

 

obj.get(name)
An accessor that you can use to retrieve the value of properties.

 

obj.set(name, value)
An accessor that you can use to set the value of properties.

 

obj.getAngle(value)
This method will return you an appropriate angle for the given value.

 

obj.on(event, func)

This method can be used to set an event listener on an object. It operates in a similar way to the jQuery .on() function - the first argument is the event you wish to attach to and the second is the handler function. For example:

.on('draw', function (obj)
{
    // Put event code here
});

The function is useful if you use method chaining when creating your charts:

var obj = new RGraph.Meter({
    id: 'cvs',
    min: 0,
    max: 100,
    value: 56
}).on('draw', function (e, shape)
{
    // Put ondraw code here
})
.on('click', function (e, shape)
{
    // Handle click event
}).draw()

 

The exec option and method

The exec function is documented here.

 

Effects

These effects are available and can be used instead of the .draw() function. There are also generic effects available which you can see here: Generic effects and transitions
<script>
    /**
    * Optional callback function that's called when the effect is complete
    */
    function myCallback (obj)
    {
        // ...
    }

    var obj = new RGraph.Meter({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 56,
        options: {
            gutterLeft: 35
        }
    }).grow({frames: 60}, myCallback);
</script>

Comments