0

I am referring to :

Changing the shapes of points in scatter plot

But Am not able to see the shape of my x,y data points:

public void plotHysteresis()
       {

        s1= new double[6];
        s2= new double[6];
        s3= new double[6];
        s4= new double[6];

        int i=0;
        for(i=0;i<6;i++)
           {
               s1[i]=hyst[i];
               System.out.println("s1[" +i +"] : " +s1[i] +"\n");
               }
        for(i=0;i<6;i++)
           {
               s2[i]=hyst[10-i];
               System.out.println("s2[" +i +"] : " +s2[i] +"\n");
               }
        for(i=0;i<6;i++)
               {
                   s3[i]=hyst[11+i];
                   System.out.println("s3[" +i +"] : " +s3[i] +"\n");
               }
        for(i=0;i<6;i++)
                       {
                           s4[i]=hyst[21-i];
                           System.out.println("s4[" +i +"] : " +s4[i] +"\n");
               }

       // DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        XYSeries series3 = new XYSeries("III");
        int x=-25;
        System.out.println(x +"***\n");
        for(i=5;i>=0;i--)
        {

            series3.add(x,s3[i]);
            x=x+5;

        }
        System.out.println(x +"***\n");
        XYSeries series4 = new XYSeries("IV");
        for(i=0;i<6;i++)
        {
            x=x-5;
            series4.add(x,s4[i] );

        }
         System.out.println(x +"###\n");
         XYSeries series1 = new XYSeries("I");
         x=0;
        for(i=0;i<6;i++)
        {
            series1.add(x,s1[i] );
            x=x+5;
        }
       // x=x-5;
        System.out.println(x +"***\n");
        XYSeries series2 = new XYSeries("II");
        for(i=5;i>=0;i--)
        {
            x=x-5;
            series2.add(x,s2[i] );

        }
        System.out.println(x +"***\n");

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series3);
        dataset.addSeries(series4);
        dataset.addSeries(series1);
        dataset.addSeries(series2);

        JFreeChart chart = ChartFactory.createXYLineChart(
    "Hysteresis Plot", // chart title
    "Pounds(lb)", // domain axis label
    "Movement(inch)", // range axis label
    dataset, // data
    PlotOrientation.VERTICAL, // orientation
    false, // include legend
    true, // tooltips
    false // urls
    );


        chart.setBackgroundPaint(Color.white);

        //chart.setBackgroundPaint(new Color(249, 231, 236));
        /*CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setRangeGridlinePaint(Color.white);
        plot.getRenderer().setSeriesPaint(0, Color.BLUE);
        plot.getRenderer().setSeriesPaint(1, Color.BLUE);
        plot.getRenderer().setSeriesPaint(2, Color.BLUE);
        plot.getRenderer().setSeriesPaint(3, Color.BLUE);*/
        Shape cross = ShapeUtilities.createRegularCross(4, 3);

        XYPlot plot = (XYPlot) chart.getPlot();
        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, Color.RED);
        renderer.setSeriesPaint(2, Color.RED);
        renderer.setSeriesPaint(3, Color.RED);

        renderer.setSeriesShape(0, cross);
        renderer.setSeriesShape(1, cross);
        renderer.setSeriesShape(2, cross);
        renderer.setSeriesShape(3, cross);
        renderer.setSeriesVisible(0,true);
        renderer.setSeriesVisible(1,true);
        renderer.setSeriesVisible(2,true);
        renderer.setSeriesVisible(3,true);

        plot.setDomainCrosshairVisible(true);//Sets Y axis visible blue
        plot.setRangeCrosshairVisible(true);//Sets X axis visible blue


        /*LineAndShapeRenderer rend
    = (LineAndShapeRenderer) plot.getRenderer();
    rend.setShapesVisible(true);*/
    //renderer.setDrawOutlines(true);
    //renderer.setUseFillPaint(true);
    //renderer.setFillPaint(Color.white);

        ChartPanel frame = new ChartPanel(chart);
        frame.setVisible(true);
        frame.setSize(plotPanel.getWidth(),plotPanel.getHeight());
        plotPanel.add(frame);
        plotPanel.repaint();
       }

The above code gives me output:

enter image description here

Earlier I was able to see the shape with CategoryPlot and LineChart as shown in commented part of the code, but it is not working for XYLineChart.

Please help Thanks

Got the solution at: How to get diamond shape for points in JFreechart Can I change the color of plot.setDomainCrosshairVisible(true);//Sets Y axis visible blue plot.setRangeCrosshairVisible(true);//Sets X axis visible blue want to make it black instead of it appearing as blue.

Community
  • 1
  • 1
Gaurav K
  • 2,864
  • 9
  • 39
  • 68

1 Answers1

0

Ok got the answer:

How to get diamond shape for points in JFreechart

XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
r.setSeriesShape(0, ShapeUtilities.createDiamond(5));
r.setSeriesShapesVisible(0, true);

Was not adding XYLineAndShapeRenderer in my code

Community
  • 1
  • 1
Gaurav K
  • 2,864
  • 9
  • 39
  • 68