
I wanted to draw scattered chart with the input value from user to y-axis co-ordinate...can you pls help by sending code

import java.util.*;
import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.data.xy.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.*;
public class ScatteredPlot{
public static void main (String[] args){
XYSeriesCollection dataset = new XYSeriesCollection();
final XYSeries data = new XYSeries("data",false);
Scanner input=new Scanner(System.in);
System.out.print("How nmany values do you want for x and y axis: ");
int v=input.nextInt();
double xvalues[]=new double[v];
double yvalues[]=new double[v];
System.out.println("Enter values for x-axis: ");
for(int i=0;i<xvalues.length;i++){
xvalues[i]=input.nextDouble();
}
System.out.println("Enter values for y-axis: ");
for(int i=0;i<yvalues.length;i++){
yvalues[i]=input.nextDouble();
}
for(int i=0;i<xvalues.length;i++){
data.add(xvalues[i], yvalues[i]);
}
dataset.addSeries(data);
JFreeChart chart = ChartFactory.createScatterPlot(
"",
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(0, true);
plot.setRenderer(renderer);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
ApplicationFrame frame = new ApplicationFrame("Title");
frame.setContentPane(chartPanel);
frame.pack();
frame.setVisible(true);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.