public function finishLegend(&$legend = null)
    {
        if (!$this->legend) {
            throw new DcGeneralRuntimeException('Legend is missing, please create a legend first');
        }

        if ($this->property) {
            $this->finishProperty();
        }

        $event = new FinishLegendEvent($this->legend, $this);
        $this->dispatchEvent($event);
        $legend = $event->getLegend();

        if ($this->palette) {
            $this->palette->addLegend($legend);
        }

        $this->legend = null;

        return $this;
    }