A dynamically updating SVG Line chart
Summary: A dynamically updating SVG Line chart. It's aesthetically quite simple in order to keep the frame up and the movement smooth.
This is an SVG version of an older dynamic canvas Line chart. There are lots of data points in the dataset (1200) and new ones are added every 16.666 milliseconds (ie 60 frames per second).
It's purposefully not a complicated chart so that there's not much to do on each redraw. So there's no vertical grid lines or border, no X axis and no shadow.
The chart is created only once inside the
drawGraph() function and then on each
iteration a new value is added to the
The new value that's added is generated randomly but is constrained to only be a few units higher or lower than the last value in the dataset. This prevents there being large jumps in the data when new values are added.
This goes in the documents header:
<script src="RGraph.svg.common.core.js"></script> <script src="RGraph.svg.line.js"></script>Put this where you want the chart to show up:
<div style="width: 650px; height: 250px" id="cc"></div>This is the code that generates the chart: