Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:23:07+00:00 2026-05-23T17:23:07+00:00

I have thousands of points to Plot on a JFreeChart scatter plot. The problem

  • 0

I have thousands of points to Plot on a JFreeChart scatter plot.
The problem right now is that my program is plotting points with “squares”, but I need some help on how to change the Shape of points from “squares” to “dots/circles”.
Any help would be appreciated.

//*I am using ShapeUtilities,but its not changing the shape of point to “DaigonalCross” when I am Using for XYItemRenderer/XYDotRenderer–Any corrections please if anythng wrong in the code ..*///

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Shape;
import java.util.*;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYDotRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.ShapeUtilities;

public class SPlotfinal extends ApplicationFrame {

    public SPlotfinal(String s) {
        super(s);
        JPanel jpanel = createDemoPanel();
        jpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(jpanel);
    }

    public static JPanel createDemoPanel() {

        JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter Plot Demo",
            "X", "Y", samplexydataset2(), PlotOrientation.VERTICAL, true, true, false);
        Shape cross = ShapeUtilities.createDiagonalCross(3, 1);

        XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
        XYItemRenderer renderer = xyPlot.getRenderer();
        renderer.setBaseShape(cross);
        renderer.setBasePaint(Color.red);
        //changing the Renderer to XYDotRenderer
        //xyPlot.setRenderer(new XYDotRenderer());
        XYDotRenderer xydotrenderer = new XYDotRenderer();
        xyPlot.setRenderer(xydotrenderer);
        xydotrenderer.setSeriesShape(0, cross);

        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setRangeCrosshairVisible(true);

        return new ChartPanel(jfreechart);
    }

    private static XYDataset samplexydataset2() {
        int cols = 20;
        int rows = 20;
        double[][] values = new double[cols][rows];

        XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries("Random");
        Random rand = new Random();
        for (int i = 0; i < values.length; i++) {
            for (int j = 0; j < values[i].length; j++) {
                double x = Math.round(rand.nextDouble() * 500);
                double y = Math.round(rand.nextDouble() * 500);

                series.add(x, y);
            }
        }
        xySeriesCollection.addSeries(series);
        return xySeriesCollection;
    }

    public static void main(String args[]) {
        SPlotfinal scatterplotdemo4 = new SPlotfinal("Scatter Plot Demo 4");
        scatterplotdemo4.pack();
        RefineryUtilities.centerFrameOnScreen(scatterplotdemo4);
        scatterplotdemo4.setVisible(true);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:23:08+00:00Added an answer on May 23, 2026 at 5:23 pm

    A ScatterRenderer inherits getItemShape() from AbstractRenderer. You can override getItemShape() to supply your own shapes.

    Addendum: One advantage to this approach is that you can specify a Shape for each item in each series.

    Addendum: To use ShapeUtilities.createDiagonalCross(), do something like this:

    Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
    plot = (XYPlot) chart.getPlot();
    renderer = plot.getRenderer();
    renderer.setSeriesShape(0, cross);
    

    Addendum: Just switch to setSeriesShape(). Also, skip the XYDotRenderer and Math.round().

    Scatter Plot Demo

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Shape;
    import java.util.*;
    import javax.swing.JPanel;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYItemRenderer;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.data.xy.XYSeries;
    import org.jfree.data.xy.XYSeriesCollection;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    import org.jfree.util.ShapeUtilities;
    
    public class SPlotfinal extends ApplicationFrame {
    
        public SPlotfinal(String s) {
            super(s);
            JPanel jpanel = createDemoPanel();
            jpanel.setPreferredSize(new Dimension(640, 480));
            add(jpanel);
        }
    
        public static JPanel createDemoPanel() {
            JFreeChart jfreechart = ChartFactory.createScatterPlot(
                "Scatter Plot Demo", "X", "Y", samplexydataset2(),
                PlotOrientation.VERTICAL, true, true, false);
            Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
            XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
            xyPlot.setDomainCrosshairVisible(true);
            xyPlot.setRangeCrosshairVisible(true);
            XYItemRenderer renderer = xyPlot.getRenderer();
            renderer.setSeriesShape(0, cross);
            renderer.setSeriesPaint(0, Color.red);
            return new ChartPanel(jfreechart);
        }
    
        private static XYDataset samplexydataset2() {
            int cols = 20;
            int rows = 20;
            double[][] values = new double[cols][rows];
            XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
            XYSeries series = new XYSeries("Random");
            Random rand = new Random();
            for (int i = 0; i < values.length; i++) {
                for (int j = 0; j < values[i].length; j++) {
                    double x = rand.nextGaussian();
                    double y = rand.nextGaussian();
                    series.add(x, y);
                }
            }
            xySeriesCollection.addSeries(series);
            return xySeriesCollection;
        }
    
        public static void main(String args[]) {
            SPlotfinal scatterplotdemo4 = new SPlotfinal("Scatter Plot Demo 4");
            scatterplotdemo4.pack();
            RefineryUtilities.centerFrameOnScreen(scatterplotdemo4);
            scatterplotdemo4.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several large csv files with thousands of columns that I need to
Developing for iPhone, I have a collection of points that I need to make
I have hundreds of thousands of points of time series data that I want
I need to plot thousands of points, perhaps close to 50,000 with the dojo
I have a very large codebase (read: thousands of modules) that has code shared
i have a log file which contains hundreds/thousands of seperate XML messages and need
I have problem optimizing drawing Google-like map. It works OK for hundreds of points,
I have a UTF-8 formatted data file that contains thousands of floating point numbers.
I am trying to plot a bunch of data points (many thousands) in Python
I have a table with thousands of addresses as points. Is there a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.