Example usage for java.awt Graphics drawLine

List of usage examples for java.awt Graphics drawLine

Introduction

In this page you can find the example usage for java.awt Graphics drawLine.

Prototype

public abstract void drawLine(int x1, int y1, int x2, int y2);

Source Link

Document

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Usage

From source file:MyJava3D.java

public void drawLine(Graphics graphics, GeometryArray geometryArray, int index, Point3d[] pointArray) {
    int intensity = computeIntensity(geometryArray, index, 2);

    if (drawBackface || intensity >= 1) {
        graphics.setColor(new Color(intensity, intensity, intensity));
        graphics.drawLine((int) pointArray[0].x, (int) pointArray[0].y, (int) pointArray[1].x,
                (int) pointArray[1].y);
    }//from   w ww. j  a  va 2  s . c  o  m
}

From source file:JavaXWin.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    m_height = getHeight();//from   w w w .  j  a  v a2  s . co  m
    m_width = getWidth();
    g.setColor(C_BACKGROUND);
    g.fillRect(0, 0, m_width, m_height);
    Component[] components = m_desktop.getComponents();
    m_widthratio = ((float) m_desktop.getWidth()) / ((float) m_width);
    m_heightratio = ((float) m_desktop.getHeight()) / ((float) m_height);
    for (int i = components.length - 1; i > -1; i--) {
        if (components[i].isVisible()) {
            g.setColor(C_UNSELECTED);
            if (components[i] instanceof JInternalFrame) {
                if (((JInternalFrame) components[i]).isSelected())
                    g.setColor(C_SELECTED);
            } else if (components[i] instanceof WindowWatcher)
                g.setColor(C_WWATCHER);
            g.fillRect((int) (((float) components[i].getX()) / m_widthratio),
                    (int) (((float) components[i].getY()) / m_heightratio),
                    (int) (((float) components[i].getWidth()) / m_widthratio),
                    (int) (((float) components[i].getHeight()) / m_heightratio));
            g.setColor(Color.black);
            g.drawRect((int) (((float) components[i].getX()) / m_widthratio),
                    (int) (((float) components[i].getY()) / m_heightratio),
                    (int) (((float) components[i].getWidth()) / m_widthratio),
                    (int) (((float) components[i].getHeight()) / m_heightratio));
        }
    }
    g.drawLine(m_width / 2, 0, m_width / 2, m_height);
    g.drawLine(0, m_height / 2, m_width, m_height / 2);
}

From source file:adams.gui.visualization.stats.paintlet.Gamma.java

/**
 * The paint routine of the paintlet.// www.  jav a  2  s .c  om
 *
 * @param g      the graphics context to use for painting
 * @param moment   what {@link PaintMoment} is currently being painted
 */
@Override
protected void doPerformPaint(Graphics g, PaintMoment moment) {
    if ((m_Data != null) && (m_Sorted != null) && m_Shape != -1.0) {
        GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled);

        for (int i = 0; i < m_Sorted.length; i++) {
            Graphics2D g2d = (Graphics2D) g;
            //If data points are to be filled
            if (m_Fill) {
                g2d.setColor(m_FillColor);
                g2d.setStroke(new BasicStroke(0));
                g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                        m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
            }
            //outline of data point
            g2d.setStroke(new BasicStroke(m_StrokeThickness));
            g2d.setColor(m_Color);
            g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                    m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
        }

        //If drawing regression fit diagonal
        if (m_RegressionLine) {
            g.setColor(Color.BLACK);
            double[] newData = new double[m_Sorted.length];
            for (int i = 0; i < m_Sorted.length; i++) {
                newData[i] = Math.log(m_Sorted[i]);
            }
            GammaDistributionImpl gd = new GammaDistributionImpl(m_Shape, m_Scale);
            //draw the expected diagonal line using the gamma distribution
            for (int i = 0; i < m_Sorted.length - 1; i++) {
                double p1;
                try {
                    p1 = gd.cumulativeProbability(newData[i]);
                } catch (MathException e) {
                    p1 = 0;
                }
                double p2;
                try {
                    p2 = gd.cumulativeProbability(newData[i + 1]);
                } catch (MathException e) {
                    p2 = 0;
                }
                g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1),
                        m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2));
            }
        }
    }
}

From source file:org.executequery.gui.editor.QueryEditorTextPane.java

/**
 * Paints the current line highlight and right-hand margin
 * before a call to the super class./*from www  .  j  a v a 2  s.com*/
 *
 * @param g the <code>Graphics</code> object to protect
 */
public void paintComponent(Graphics g) {

    int height = getHeight();
    int width = getWidth();

    g.setColor(getBackground());
    g.fillRect(0, 0, width, height);

    // paint the current line highlight
    if (QueryEditorSettings.isDisplayLineHighlight()) {
        int currentRow = getCurrentCursorRow();
        g.setColor(QueryEditorSettings.getLineHighlightColour());
        g.fillRect(1, (currentRow * fontHeight) + 2, width - 1, fontHeight);
    }

    // paint the right-hand margin
    if (QueryEditorSettings.isDisplayRightMargin()) {
        int xPosn = fontWidth * QueryEditorSettings.getRightMarginSize();
        g.setColor(QueryEditorSettings.getRightMarginColour());
        g.drawLine(xPosn, 0, xPosn, height);
    }

    try {
        super.paintComponent(g);
    } catch (Exception e) {
    }

}

From source file:adams.gui.visualization.stats.paintlet.Exponential.java

/**
 * The paint routine of the paintlet./*from  w  w w.ja va2s.  co m*/
 *
 * @param g      the graphics context to use for painting
 * @param moment   what {@link PaintMoment} is currently being painted
 */
@Override
protected void doPerformPaint(Graphics g, PaintMoment moment) {
    if ((m_Data != null) && (m_Sorted != null)) {
        GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled);

        for (int i = 0; i < m_Sorted.length; i++) {
            Graphics2D g2d = (Graphics2D) g;
            //If data points are to be filled
            if (m_Fill) {
                g2d.setColor(m_FillColor);
                g2d.setStroke(new BasicStroke(0));
                g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                        m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
            }
            //outline of data point
            g2d.setStroke(new BasicStroke(m_StrokeThickness));
            g2d.setColor(m_Color);
            g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                    m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
        }
        //if drawing regression fit diagonal
        if (m_RegressionLine) {
            g.setColor(Color.BLACK);
            double[] newData = new double[m_Sorted.length];
            for (int i = 0; i < m_Sorted.length; i++) {
                newData[i] = Math.log(m_Sorted[i]);
            }
            ExponentialDistributionImpl ex = new ExponentialDistributionImpl(StatUtils.mean(newData));
            //draw the expected diagonal line using the exponential distribution
            for (int i = 0; i < m_Sorted.length - 1; i++) {
                double prob1;
                try {
                    prob1 = ex.cumulativeProbability(newData[i]);
                } catch (MathException e) {
                    prob1 = 0;
                }
                double prob2;
                try {
                    prob2 = ex.cumulativeProbability(newData[i + 1]);
                } catch (MathException e) {
                    prob2 = 0;
                }
                double p1 = -Math.log(1 - prob1);
                double p2 = -Math.log(1 - prob2);
                g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1),
                        m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2));
            }
        }
    }
}

From source file:savant.view.swing.GraphPane.java

@Override
protected void paintComponent(Graphics g) {
    if (tracks != null && tracks.length > 0) {
        LOG.trace("GraphPane.paintComponent(" + tracks[0].getName() + ")");
    }/*  ww w  .  j  av a 2s .co m*/
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    boolean trueRender = render(g2);

    GraphPaneController gpc = GraphPaneController.getInstance();
    int h = getHeight();

    // Aiming adjustments.
    if (gpc.isAiming() && mouseInside) {
        g2.setColor(Color.BLACK);
        Font thickfont = g2.getFont().deriveFont(Font.BOLD, 15.0F);
        g2.setFont(thickfont);
        int genomeX = gpc.getMouseXPosition();
        double genomeY = gpc.getMouseYPosition();
        String target = "";
        target += "X: " + MiscUtils.numToString(genomeX);
        if (!Double.isNaN(genomeY)) {
            target += " Y: " + MiscUtils.numToString(genomeY);
        }

        g2.drawLine(mouseX, 0, mouseX, h);
        if (genomeY != -1) {
            g.drawLine(0, mouseY, this.getWidth(), mouseY);
        }
        g2.drawString(target, mouseX + 5, mouseY - 5);
    }

    double x1 = transformXPos(gpc.getMouseClickPosition());
    double x2 = transformXPos(gpc.getMouseReleasePosition());

    double width = x1 - x2;

    selectionRect = new Rectangle2D.Double(width < 0 ? x1 : x2, 0.0, Math.max(2.0, Math.abs(width)), h);

    if (gpc.isPanning()) {
        // Panning adjustments (none).
    } else if (gpc.isZooming() || gpc.isSelecting()) {
        // Zooming adjustments.
        Rectangle2D rectangle = new Rectangle2D.Double(selectionRect.getX(), selectionRect.getY() - 10.0,
                selectionRect.getWidth(), selectionRect.getHeight() + 10.0);
        g2.setColor(Color.gray);
        g2.setStroke(
                new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3f, new float[] { 4f }, 4f));
        g2.draw(rectangle);

        if (gpc.isZooming()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_ZOOM_FILL));
        } else if (gpc.isSelecting()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_SELECTION_FILL));
        }
        g2.fill(selectionRect);
    }

    // Plumbing adjustments.
    Range xRange = getXRange();
    if (gpc.isPlumbing()) {
        g2.setColor(Color.BLACK);
        double spos = transformXPos(gpc.getMouseXPosition());
        g2.draw(new Line2D.Double(spos, 0, spos, h));
        double rpos = transformXPos(gpc.getMouseXPosition() + 1);
        g2.draw(new Line2D.Double(rpos, 0, rpos, h));
    }

    // Spotlight
    if (gpc.isSpotlight() && !gpc.isZooming()) {

        int center = gpc.getMouseXPosition();
        int left = center - gpc.getSpotlightSize() / 2;
        int right = left + gpc.getSpotlightSize();

        g2.setColor(new Color(0, 0, 0, 200));

        // draw left of spotlight
        if (left >= xRange.getFrom()) {
            g2.fill(new Rectangle2D.Double(0.0, 0.0, transformXPos(left), h));
        }
        // draw right of spotlight
        if (right <= xRange.getTo()) {
            double pix = transformXPos(right);
            g2.fill(new Rectangle2D.Double(pix, 0, getWidth() - pix, h));
        }
    }

    if (isLocked()) {
        drawMessage((Graphics2D) g, "Locked");
    }
    if (trueRender) {
        gpc.delistRenderingGraphpane(this);
    }
}

From source file:se.llbit.chunky.renderer.scene.Scene.java

/**
 * Update the canvas - draw the latest rendered frame
 * @param warningText/*from  w  w  w .j  a  va2 s .com*/
 */
public synchronized void updateCanvas(String warningText) {
    finalized = false;

    try {
        // flip buffers
        BufferedImage tmp = buffer;
        buffer = backBuffer;
        backBuffer = tmp;

        bufferData = ((DataBufferInt) backBuffer.getRaster().getDataBuffer()).getData();

        Graphics g = buffer.getGraphics();

        if (!warningText.isEmpty()) {
            g.setColor(java.awt.Color.red);
            int x0 = width / 2;
            int y0 = height / 2;
            g.setFont(infoFont);
            if (fontMetrics == null) {
                fontMetrics = g.getFontMetrics();
            }
            g.drawString(warningText, x0 - fontMetrics.stringWidth(warningText) / 2, y0);
        } else {

            if (renderState == RenderState.PREVIEW) {
                int x0 = width / 2;
                int y0 = height / 2;
                g.setColor(java.awt.Color.white);
                g.drawLine(x0, y0 - 4, x0, y0 + 4);
                g.drawLine(x0 - 4, y0, x0 + 4, y0);
                g.setFont(infoFont);
                Ray ray = new Ray();
                if (trace(ray) && ray.getCurrentMaterial() instanceof Block) {
                    Block block = (Block) ray.getCurrentMaterial();
                    g.drawString(String.format("target: %.2f m", ray.distance), 5, height - 18);
                    g.drawString(String.format("[0x%08X] %s (%s)", ray.getCurrentData(), block,
                            block.description(ray.getBlockData())), 5, height - 5);
                }
                Vector3d pos = camera.getPosition();
                g.drawString(String.format("(%.1f, %.1f, %.1f)", pos.x, pos.y, pos.z), 5, 11);
            }
        }

        g.dispose();
    } catch (IllegalStateException e) {
        Log.error("Unexpected exception while rendering back buffer", e);
    }
}

From source file:ded.ui.DiagramController.java

/** The core of the paint routine, after we decide whether to interpose
  * another buffer. */// w  w  w  .  ja  v  a  2 s .  co  m
private void innerPaint(Graphics g) {
    super.paint(g);

    // I do not know the proper way to get a font set automatically
    // in a Graphics object.  Calling JComponent.setFont has gotten
    // me nowhere.  Setting it myself when I first get control
    // seems to work; but note that I have to do this *after*
    // calling super.paint().
    g.setFont(this.dedWindow.diagramFont);

    // Filename label.
    if (this.diagram.drawFileName && !this.fileName.isEmpty()) {
        String name = new File(this.fileName).getName();
        FontMetrics fm = g.getFontMetrics();
        LineMetrics lm = fm.getLineMetrics(name, g);
        int x = fileNameLabelMargin;
        int y = fileNameLabelMargin + (int) lm.getAscent();
        g.drawString(name, x, y);
        y += (int) lm.getUnderlineOffset() + 1 /*...*/;
        g.drawLine(x, y, x + fm.stringWidth(name), y);
    }

    // Controllers.
    for (Controller c : this.controllers) {
        if (c.isSelected()) {
            c.paintSelectionBackground(g);
        }
        c.paint(g);
    }

    // Lasso rectangle.
    if (this.mode == Mode.DCM_RECT_LASSO) {
        Rectangle r = this.getLassoRect();
        g.drawRect(r.x, r.y, r.width, r.height);
    }

    // Current focused Component.
    if (debugFocus) {
        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        Component fo = kfm.getFocusOwner();
        g.drawString("Focus: " + fo, 3, this.getHeight() - 22);
    }

    // Mode label.
    if (this.mode != Mode.DCM_SELECT) {
        g.drawString("Mode: " + this.mode.description, 3, this.getHeight() - 4);
    } else if (this.fpsMeasurementMode) {
        this.fpsFrameCount++;
        long current = System.currentTimeMillis();
        long millis = current - this.fpsStartMillis;
        if (millis > 1000) {
            // Update the FPS measurement with the results for this
            // interval.
            this.fpsSampleCount++;
            this.fpsMeasurement = "FPS: " + this.fpsFrameCount + " (millis=" + millis + ", samples="
                    + this.fpsSampleCount + ")";

            // Reset the counters.
            this.fpsStartMillis = current;
            this.fpsFrameCount = 0;
        }
        g.drawString(this.fpsMeasurement + " (Ctrl+G to stop)", 3, this.getHeight() - 4);
    }
}

From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java

@Override
protected void paintComponent(Graphics g) {

    g.setColor(Color.WHITE);/*w  ww.  ja  va 2 s  . co  m*/
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLACK);

    if (g instanceof Graphics2D) {
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }

    double yStart, xStart;
    if (minY % yInterval == 0) {
        yStart = minY;
    } else {
        yStart = yInterval * (((int) minY / yInterval) + 1);
    }

    if (minX % xInterval == 0) {
        xStart = minX;
    } else {
        xStart = xInterval * (((int) minX / xInterval) + 1);
    }

    int xOffset = 0;

    // Draw the yLabel on the left of the yAxis
    int yLabelRightShift = 12;
    if (yLabel == null || yLabel.isEmpty()) {
        yLabelRightShift = 0;
    } else {
        if (g instanceof Graphics2D) {
            Graphics2D g2 = (Graphics2D) g;
            AffineTransform orig = g2.getTransform();
            g2.rotate(-Math.PI / 2);
            g2.setColor(Color.BLACK);
            g2.drawString(yLabel, -getY(-yInterval) / 2 - (g.getFontMetrics().stringWidth(yLabel) / 2),
                    yLabelRightShift);
            g2.setTransform(orig);
        }
    }

    // Draw the y axis labels
    int lastYLabelEnd = Integer.MAX_VALUE;
    for (double i = yStart; i <= maxY; i += yInterval) {
        String label = "" + i;
        label = label.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them.
        // Calculate the new xOffset depending on the widest ylabel.
        int width = g.getFontMetrics().stringWidth(label);
        if (width > xOffset) {
            xOffset = width;
        }
        // place the y axis labels so that they don't overlap when the plot is resized.
        int baseNumberHeight = g.getFontMetrics().getHeight();
        int baseNumberPosition = getY(i) + (baseNumberHeight / 2);
        if (baseNumberPosition + baseNumberHeight < lastYLabelEnd) {
            // Draw the y axis labels
            g.drawString(label, yLabelRightShift + 6, baseNumberPosition);
            lastYLabelEnd = baseNumberPosition + 2;
        }
    }

    // Give the x axis a bit of breathing space
    xOffset = xOffset + yLabelRightShift + 8;

    // Now draw horizontal lines across from the y axis
    g.setColor(new Color(180, 180, 180));
    for (double i = yStart; i <= maxY; i += yInterval) {
        g.drawLine(xOffset, getY(i), getWidth() - 10, getY(i));
    }
    g.setColor(Color.BLACK);

    // Draw the graph title
    int titleWidth = g.getFontMetrics().stringWidth(graphTitle);
    g.drawString(graphTitle, (xOffset + ((getWidth() - (xOffset + 10)) / 2)) - (titleWidth / 2), 30);

    // Draw the xLabel under the xAxis
    g.drawString(xLabel, (getWidth() / 2) - (g.getFontMetrics().stringWidth(xLabel) / 2), getHeight() - 5);

    // Now draw the data points
    double baseWidth = (getWidth() - (xOffset + 10)) / (maxX - minX);

    //      System.out.println("Base Width is "+baseWidth);
    // Let's find the longest label, and then work out how often we can draw labels
    int lastXLabelEnd = 0;

    // Draw the x axis labels
    for (double i = xStart; i <= maxX; i += xInterval) {
        g.setColor(Color.BLACK);
        String baseNumber = "" + i;
        baseNumber = baseNumber.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them.
        // Calculate the new xOffset depending on the widest ylabel.
        int baseNumberWidth = g.getFontMetrics().stringWidth(baseNumber);
        int baseNumberPosition = (int) (xOffset + (baseWidth * i) - (baseNumberWidth / 2));

        if (baseNumberPosition > lastXLabelEnd) {
            g.drawString(baseNumber, baseNumberPosition, getHeight() - 25);
            lastXLabelEnd = baseNumberPosition + baseNumberWidth + 5;
        }
        // Now draw vertical lines across from the y axis
        g.setColor(new Color(180, 180, 180));
        g.drawLine((int) (xOffset + (baseWidth * i)), getHeight() - 40, (int) (xOffset + (baseWidth * i)), 40);
        g.setColor(Color.BLACK);
    }

    // Now draw the axes
    g.drawLine(xOffset, getHeight() - 40, getWidth() - 10, getHeight() - 40);
    g.drawLine(xOffset, getHeight() - 40, xOffset, 40);

    // Initialise the arrays containing the tooltips
    rectangles = new ArrayList<Rectangle>();
    tips = new ArrayList<String>();

    g.setColor(Color.BLUE);
    // Draw the data points
    double ovalSize = 5;
    // We distinguish two inputs since the x label does not start from 0.
    // used for computing the actual line points as if they were starting from 0.
    double[] inputVar = new double[data.length];
    double[] responseVar = new double[data.length];
    for (int d = 0; d < data.length; d++) {
        double x = getX(xCategories[d], xOffset) - ovalSize / 2;
        double y = getY(data[d]) - ovalSize / 2;
        g.fillOval((int) x, (int) y, (int) (ovalSize), (int) (ovalSize));
        g.drawString(toolTipLabels[d], (int) x + 2, (int) y + 16);
        inputVar[d] = Double.valueOf(xCategories[d]);
        responseVar[d] = data[d];

        // Tool tips
        Rectangle r = new Rectangle((int) x, (int) y, (int) (ovalSize), (int) (ovalSize));
        rectangles.add(r);
        tips.add(toolTipLabels[d]);
    }
    g.setColor(Color.BLACK);

    // Draw the intercept 

    // WARNING: Is drawing a least squares regression line asserting that "the distribution follows a power law" correct?
    // This is our case if we plot log-log..
    // It seems not in this paper (Appendix A) http://arxiv.org/pdf/0706.1062v2.pdf

    if (data.length > 1) {
        LinearRegression linReg = new LinearRegression(inputVar, responseVar);
        double intercept = linReg.intercept();
        double slope = linReg.slope();
        double rSquare = linReg.R2();

        // Let's now calculate the two points (x1, y1) and (xn, yn)
        // (x1, y1). We need to skip the areas where x1<minY and y1>maxY
        double x1 = minX;
        double y1 = slope * minX + intercept;
        if (y1 < minY) {
            x1 = (minY - intercept) / slope;
            y1 = minY;
        } else if (y1 > maxY) {
            x1 = (maxY - intercept) / slope;
            y1 = maxY;
        }
        // (xn, yn). maxX which essentially is inputVar[inputVar.length-1]
        double xn = maxX;
        double yn = slope * maxX + intercept;

        if (g instanceof Graphics2D) {
            ((Graphics2D) g).setStroke(new BasicStroke(1.5f));
        }
        g.setColor(Color.RED);
        g.drawLine(getX(x1, xOffset), getY(y1), getX(xn, xOffset), getY(yn));
        g.setColor(Color.BLACK);
        if (g instanceof Graphics2D) {
            ((Graphics2D) g).setStroke(new BasicStroke(1));
        }

        // Draw the legend for the intercept
        String legendString = "y = " + Precision.round(slope, 3) + "x";
        if (intercept < 0)
            legendString += " - " + Precision.round(-intercept, 3);
        else
            legendString += " + " + Precision.round(intercept, 3);
        int width = g.getFontMetrics().stringWidth(legendString);

        // First draw a box to put the legend in
        g.setColor(Color.WHITE);
        g.fillRect(xOffset + 10, 45, width + 8, 35);
        g.setColor(Color.LIGHT_GRAY);
        g.drawRect(xOffset + 10, 45, width + 8, 35);

        // Now draw the legend label
        g.setColor(Color.RED);
        g.drawString(legendString, xOffset + 13, 60);
        g.drawString("R^2 = " + Precision.round(rSquare, 3), xOffset + 13, 76);
        g.setColor(Color.BLACK);
    }

}