How to generate a legend with colors in PlantUML?

Masked Man picture Masked Man · Jun 23, 2015 · Viewed 7.1k times · Source

I want to color classes in my class diagram, based on a certain criteria, and then display a legend, that would look roughly like:

Legend with colors

If I could add an HTML table within PlantUML's legend and endlegend, I could achieve this by changing the cell backgrounds. However, adding the HTML <table> doesn't work. I also tried using PlantUML's salt to insert a table, but I couldn't find any way to color the cells of the table.

Is there any way to achieve this?

Answer

AmaDaden picture AmaDaden · May 27, 2017

I've tried nfec's solution and it was not working for me, but it started me off on a solution that did work. Here is what I got:

legend right
    |Color| Type |
    |<#FF0000>| Type A class|
    |<#00FF00>| Type B class|
    |<#0000FF>| Type C class|
endlegend

This is how it looks like:

Legend color table