code: private Rectangle2D getBoundsHintHorizontal() {
  
      if (!chart.getStyler().isLegendVisible()) {
        return new Rectangle2D
            .Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
        // 0).
      }
  
      // determine legend text content max height
      double legendTextContentMaxHeight = 0;
  
      // determine total legend content width
      double legendContentWidth = 0;
  
      Map<String, S> map = chart.getSeriesMap();
      for (S series : map.values()) {
  
        if (!series.isShowInLegend()) {
          continue;
        }
        if (!series.isEnabled()) {
          continue;
        }
  
        Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
  
        double legendEntryHeight = 0; // could be multi-line
        double legendEntryMaxWidth = 0; // could be multi-line
        for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
          legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE;
          legendEntryMaxWidth = Math.max(legendEntryMaxWidth, entry.getValue().getWidth());
        }
  
        legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE
        legendTextContentMaxHeight =
            Math.max(legendEntryHeight, getSeriesLegendRenderGraphicHeight(series));
  
        legendContentWidth += legendEntryMaxWidth + chart.getStyler().getLegendPadding();
  
        if (series.getLegendRenderType() == LegendRenderType.Line) {
          legendContentWidth =
              chart.getStyler().getLegendSeriesLineLength()
                  + chart.getStyler().getLegendPadding()
                  + legendContentWidth;
        } else {
          legendContentWidth = BOX_SIZE + chart.getStyler().getLegendPadding() + legendContentWidth;
        }
      }
  
      // Legend Box
      double width = legendContentWidth + chart.getStyler().getLegendPadding();
      double height = legendTextContentMaxHeight + chart.getStyler().getLegendPadding() * 2;
  
      return new Rectangle2D.Double(0, 0, width, height); // 0 indicates not sure yet.
    }
docs: determine the width and height of the chart legend with horizontal layout