Hello there was a problem with the search in the documentation information: (Namely, what I didn’t find is how to change the line type, its color and how to add labels to the points. An example of how I have and how I would like to see attached below, as well as code :

1) The screen is how it should be (at each point X, the value Y should be put on the graph)

2) What it looks like now That is how it should be (at each point X, the value of Y should be put on the graph Thats how i have now

XYSeries series = new XYSeries(" "); for(float i = 0; i < 16; i+=0.1){ series.add(i, (2 * u) / q * Math.abs((sin(i * 3.14 / q)) / (i * 3.14 / q))); } XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory .createXYLineChart("График", "x", "y", xyDataset, PlotOrientation.VERTICAL, true, true, true); JFrame frame = new JFrame("График"); // Помещаем график на фрейм frame.getContentPane() .add(new ChartPanel(chart)); frame.setSize(720,480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); 
  • And you did not try to use JavaFX LineChart? I think he is better than JFreeChart - Vanguard 1:28 pm

1 answer 1

And so, having spent a little time studying the sources and forums, I still found the answers to my questions.

1) Line type (I needed a dashed line) I used the JFreeChart library and to change the line type we use the class XYLineAndShapeRenderer. And it has a setSeriesStroke method. An example of how I have here

  XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesStroke( 0, new BasicStroke( 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[]{2.0f, 10.0f}, 0.0f ) ); 

2) Line color Use the same XYLineAndShapeRenderer, namely the ego method SetPaint.

 renderer.setPaint(Color.red); 

3) Signatures to the points. Create an instance of the XYPlot class. To solve the problem, I used the XYTextAnnotation class, which needs to be passed (String text, double x, double y) (after that we use the addAnnotation XYPlot method).

 XYPlot plot = (XYPlot) chart.getPlot(); XYTextAnnotation textAnnotation = new XYTextAnnotation(String.valueOf("Подпись", Координата X, Координата Y); plot.addAnnotation(textAnnotation);