james james - 7 months ago 10
Java Question

How to show data values on a graph as "x" in Java Swing?

I am using Swing library to plot a simple line graph. To show the data values in the graph I use Graphics.fillOval to create a dot, which represents the data. But how do I show the data values as a small "x" instead of a dot?

Answer

For example, you can draw a figure like "x" by drawing two lines.

Example:

void drawX(Graphics g, int x, int y, int size) {
    g.drawLine(x - size, y - size, x + size, y + size);
    g.drawLine(x + size, y - size, x - size, y + size);
}
Comments