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