@Override public void paint(Graphics g) { super.paint(g); // set where inside the dialog, the chart needs to be drawn Rectangle clip = new Rectangle(PAD, PAD, getWidth() - (2 * PAD), getHeight() - (2 * PAD)); // draw the background of the chart drawChartBackground(g, clip); // set the position of the axis in case they moved if (yAxis.isLogScale()) { xAxis.setPosition(yAxis.dataValueToScreenPosition(1, clip)); } else { xAxis.setPosition(yAxis.dataValueToScreenPosition(0, clip)); } if (xAxis.isLogScale()) { yAxis.setPosition(xAxis.dataValueToScreenPosition(1, clip)); } else { yAxis.setPosition(xAxis.dataValueToScreenPosition(0, clip)); } // draw the grid xAxis.drawGrid(g, clip); yAxis.drawGrid(g, clip); // draw the curve drawGraphics(g, clip, chartType); // draw the axis xAxis.drawAxis(g, clip); yAxis.drawAxis(g, clip); // draw minor units xAxis.drawMinorUnit(g, clip); yAxis.drawMinorUnit(g, clip); // draw major units xAxis.drawMajorUnit(g, clip); yAxis.drawMajorUnit(g, clip); // draw the chart legend drawLegend(g); }
/** * Method to translate the coordinates of the data point to the point on screen * * @param x x component of a data point * @param y y component of a data point * @return Point */ private Point getTranslatedPoint(double x, double y) { Point translatedPoint = new Point(); int realWidth = getWidth() - (2 * PAD); int realHeight = getHeight() - (2 * PAD); Rectangle clip = new Rectangle(PAD, PAD, realWidth, realHeight); translatedPoint.x = xAxis.dataValueToScreenPosition(x, clip); translatedPoint.y = yAxis.dataValueToScreenPosition(y, clip); return translatedPoint; }