Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging the shapes of points in scatter plot
    primarykey
    data
    text
    <p>I have thousands of points to Plot on a <code>JFreeChart</code> 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 <code>Shape</code> of points from "squares" to "dots/circles". Any help would be appreciated.</p> <p>//<strong>*<em>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 ..</em>*</strong>///</p> <pre><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 &lt; values.length; i++) { for (int j = 0; j &lt; 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload