Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js - generateLegend() call results in "undefined is not a function"

Tags:

chart.js

When I attempt to call generateLegened() on my chart:

var ctx = $("#chart").get(0).getContext("2d");
var ctxOptions = {
    responsive: false,
    legendTemplate: "<ul>LEGEND</ul>"
};
var chart = new Chart(ctx);

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

it errors with:

Uncaught TypeError: undefined is not a function

on the chart.GenerateLegend() line.

I'm completely confused as to what the problem it. The function is clearly in the .js file being included.

I'm using this script: //cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1/Chart.min.js

Is this a bug, or can someone tell me what I'm doing wrong?

Thanks

like image 726
Leigh Bowers Avatar asked Jan 30 '15 13:01

Leigh Bowers


2 Answers

Interestingly, if I change the code as follows:

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

the legend works as expected!?

A bug with chart.js?

like image 97
Leigh Bowers Avatar answered Oct 12 '22 01:10

Leigh Bowers


Try

legendTemplate: function(data) { return "<ul>LEGEND</ul>"; }

instead. Seems like some bug in the chart.js.

like image 33
Gherman Avatar answered Oct 12 '22 02:10

Gherman