This is quite an old demo of a Line chart but it has stood up through the years very well and still looks very presentable.
It's a black Line chart with two datasets that both use custom tickmarks.
These custom tickmarks are drawn by utilising the RGraph.path2()
API
function. This is a function that makes drawing with the canvas API
far less verbose than it usually is.
Before drawing commences, using the beforedraw
event, the canvas
is cleared
to a plain black color. You might find this as a performance enhancing tip
on various canvas performance articles though by the second frame you'll
not be drawing on a transparent canvas - so it might be a redundant
action.
The trace()
Line chart effect is used here - but an options
object is passed
to the effects function call. This is just a regular JavaScript object which
contains a single property: frames
As the name suggests this stipulates the number of frames in the animation.
Lower numbers make for quicker animations that finish sooner.
<script src="RGraph.common.core.js"></script> <script src="RGraph.line.js"></script>Put this where you want the chart to show up:
<canvas id="cvs" width="600" height="250" style="border-radius: 5px; box-shadow: 3px 3px 3px #ccc"> [No canvas support] </canvas>This is the code that generates the chart:
<script> new RGraph.Line({ id: 'cvs', data: [ [7.0,6.9,9.5,14.5,18.2,21.5,25.2,26.5,23.3,18.3,13.9,9.6], [0.2,0.8,5.7,11.3,17.0,22.0,24.8,24.1,20.1,14.1,8.6, 2.5] ], options: { xaxisLabels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], shadow: false, backgroundGridBorder: true, axes: false, colors: ['#0f0','#76D0FF'], tickmarksStyle: function (obj, data, value, index, x, y, color, prevX, prevY) { RGraph.path2( obj.context, 'b lw 2 a % % 6 0 % false f null s black', x, y, RGraph.TWOPI ); }, linewidth: 3, textColor: '#eee', marginLeft: 40, marginBottom: 40, marginTop: 40, marginRight: 40 } }).on('beforedraw', function (obj) { RGraph.clear(obj.canvas, 'black'); }).trace2({frames: 15}); </script>