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(); } }