Skip to content

Novis\Spreadsheet\Chart::Legend

Where a chart shows its legend, the list of series names and their colors.

You set it with the option legend of Chart::column and the other methods that make a chart. That method converts the string to a Chart::Legend case:

  • 'top', 'right', 'bottom' and 'left' are Top, Right, Bottom and Left.
  • 'hidden' is Hidden. The chart has no legend.

Without the option, the legend is Right. Any other string throws a LogicError. The property legend of a Chart is one of these cases.

Examples

Where the legend goes

<?nvs
// Shows the `Chart::Legend` that each value of the chart option `legend` gives.
use Novis\Spreadsheet\Chart;
class Legends
{
public static function name(Chart::Legend $legend): string
{
return match ($legend) {
Chart::Legend::Hidden => 'Hidden',
Chart::Legend::Top => 'Top',
Chart::Legend::Right => 'Right',
Chart::Legend::Bottom => 'Bottom',
Chart::Legend::Left => 'Left',
};
}
}
// Without the option, the legend is on the right. This prints "Right".
echo Legends::name(Chart::column()->legend), "\n";
// This prints "Bottom".
echo Legends::name(Chart::pie({ legend: 'bottom' })->legend), "\n";
// A chart with one series often needs no legend. This prints "Hidden".
echo Legends::name(Chart::line({ legend: 'hidden' })->legend), "\n";
Output
Right
Bottom
Hidden