Plotting data points with a line chart

If you've ever taken a science class, you're probably familiar with generating line charts based on a set of data for your experiments. Line charts are probably one of the most useful data visualizations when communicating data trends. In this recipe, we'll create a configurable Line Chart class which takes in an array of data elements and plots each point while connecting the points with line segments.

Plotting data points with a line chart

How to do it...

Follow these steps to create a Line Chart class that can automatically position and size a line chart from an array of data:

  1. Define the constructor for the LineChart class that draws the x and y ...

Get HTML5 Canvas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.