nnnick/Chart.js — pull request #177 by ngallagher87 (2013-07-11 20:19:57+00:00)
Title: Add legend for line charts

# Line chart legends

This pull request adds an option to show a legend for a line chart. The legend is optional, but if enabled requires the `title` field to be defined in the dataset:

_Example dataset with showLegend_

var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [65,59,90,81,56,55,40],
//Optional: Add this if you want to show a legend
title : "Foo"
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28,48,40,19,96,27,100],
//Optional: Add this if you want to show a legend
title : "Bar"
}
]
}

This produces something like this:

![](https://www.evernote.com/shard/s229/sh/67279ab3-dbc3-41ac-9254-f62834367a67/d5b2fd033ec5f7552a7ee6cdc3279846/deep/0/Line%20Chart.png)

The pull request also includes updates to documentation and samples.

## Notes

The visuals are a bit underwhelming - If this is an idea you like, I can spend more time to work out a nicer looking legend.