You can pass a jquery element in the plot's legend settings to get flot to generate this for you. https://github.com/flot/flot/blob/master/API.md#customizing-the-legend