Exemplo n.º 1
0
  private void drawLegend(Context2D context) {
    if (legend != null && drawLegend) {
      legend.setContext(context);
      double tX = 0;
      double tY = 0;
      double offsetTop = calculateOffsetCausedByTitleAndSubtitle(context);
      Legend.LegendPosition position = legend.getPosition();

      if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)) {
        tX = paddingLeft;
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_RIGHT)) {
        tX = width - paddingRight - legend.getWidth();
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_TOP)) {
        tX = paddingLeft;
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_BOTTOM)) {
        tX = paddingLeft;
        tY = height - paddingBottom - legend.getHeight();
      }
      context.save();
      context.translate(tX, tY);
      legend.draw();
      context.restore();
    }
  }
Exemplo n.º 2
0
  private void drawChart(Context2D context) {
    if (renderer != null) {
      double offsetTop = calculateOffsetCausedByTitleAndSubtitle(context);
      double chartWidth = width - paddingLeft - paddingRight;
      double chartHeight = height - offsetTop - paddingBottom;

      context.save();
      context.translate(paddingLeft, offsetTop);

      if (drawLegend && legend != null) {
        Legend.LegendPosition position = legend.getPosition();
        if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)
            || position.equals(Legend.LegendPosition.LEGEND_POSITION_RIGHT)) {

          chartWidth -= legend.getWidth() + legendMargin;

          if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)) {
            context.translate(legend.getWidth() + legendMargin, 0);
          }

        } else {
          chartHeight -= legend.getHeight() + legendMargin;
          if (position.equals(Legend.LegendPosition.LEGEND_POSITION_TOP)) {
            context.translate(0, legend.getHeight() + legendMargin);
          }
        }
      }

      context.resize(chartWidth, chartHeight);
      renderer.draw(context, dataseries, labels);
      context.restore();
    }
  }