New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate legend not found #6
Comments
@youknowriad Please PR 😄 |
I met the same problem with legend, could some one help to figure out or fix the issue |
The nchart 1.0.0 will be updated to the latest APIs of |
@youknowriad @Tommassissimo |
It worked perfectly with last version. Thanks a lot :) |
Please, could I have an example of how to use it? Is it possible to see the legend in the generated png? |
I have seen all the examples @fundon but I dont see anything about legends (or I am missing something). About legends I mean, in a linear graph with three data sets, a legend with titles for each data set (line). |
@jgato In my use case, I generate an image from the canvas and us wkhtmtopdf to generate a pdf with the image and the html of the legend with a code like this // imageFile contains the filename of the image generated from nchart canvas
$ = cheerio.load('<div><style>' +
'.chartjs-legend li {display: inline-block;margin: 0 5px;} ' +
'.chartjs-legend .pill {display: inline-block;width: 8px;height: 8px;border-radius: 2px;margin-right: 3px;} '+
'.chartjs-legend {list-style: none;text-align: center;} ' +
'</style></div>');
$('div').append('<img src="file://'+imageFile+'" />');
$('div').append(chart.generateLegend()); and the generated pdf looks like |
But, is it possible to generate the image containing the labels? Using object.generateLegend() I get the html code regarding the lables. How can I include that in the picture? Do I need to insert that into the canvas? Sorry because I have never used canvas before. |
I think the best you could do, is using a trick like me and use wkhtmltoimage : First generate an html containing the image of the graph and the html of the legend than transform this html to an image using wkhtmltoimage |
Thanks @youknowriad cheerion was the piece that I was missing, now I almost got it. I have the legend, but not with the colours of the series. How can I get that? I guess I will need to modify the legendTemplate option, but I dont know how. By the way the code to get that, just if it is useful for other people:
|
@jgato you're absolutely right I use something like this for the legendTemplate chartOptions = {
legendTemplate : '<ul class="chartjs-legend <%=name.toLowerCase()%>-legend"><% for (var i=0; i<datasets.length; i++){%><li><span class="pill" style="background-color:<%=datasets[i].strokeColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
}; |
Hi,
I have a small issue with legends, Chart.js has a generateLegend method to generate an html legend (based on legends templates). When I try this in nchart i get a not found function. Can this be added to nchart ?
Thanks
The text was updated successfully, but these errors were encountered: