generateLegend() results in an “undefined is not a function” error

The generatLegend() function only seems to work when a chart is created as follows:

var chart = new Chart(ctx).Line(data, ctxOptions);
var legend = chart.generateLegend();

The following does not work, and result in an “undefined is not a function” error:

var chart = new Chart(ctx);
chart.Line(data, ctxOptions);
var legend = chart.generateLegend();

See http://stackoverflow.com/questions/28236561/chart-js-generatelegend-call-results-in-undefined-is-not-a-function/28347373#28347373

Author: Fantashit

1 thought on “generateLegend() results in an “undefined is not a function” error

  1. chart.Line(…) doesn’t modify your chart object in place, and the proto isn’t updated with generateLegend() until after you’ve called a chart type on your chart object.

    var chart = new Chart(ctx);
    var lineChart = chart.Line(data, ctxOptions);
    var legend = lineChart.generateLegend();

Comments are closed.