4

I just want to add additional details about the chart. how can i include additional details like in the below pic.

enter image description here

A.Mohamed Bilal
  • 115
  • 1
  • 13

3 Answers3

3
    final Marker start = new ValueMarker(3400000.0);
    start.setPaint(Color.red);
    start.setLabel("Current Value");
    start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addRangeMarker(start);

34,00,000 is counter value. Set counter value as per your need. On (x,y) Axis.

Java Man
  • 1,854
  • 3
  • 21
  • 43
1

Try the annotations (e.g., XYDrawableAnnotation). Here's an example:

http://www.java2s.com/Code/Java/Chart/JFreeChartMarkerDemo1.htm

rlegendi
  • 10,466
  • 3
  • 38
  • 50
1

You can modify the chart using graphics object. For getting the graphics object of chart:

  1. Create chart.
  2. Get the buffered image of the graph.
  3. fetch buffered image graphics and modify them.
  4. Convert modified buffered image into the png or jpg format.

Following is the code snippet:

// fetch chart as buffered image    
BufferedImage image = chart.createBufferedImage(width, height);
// fetch graphics from the buffered image for perform modifications.
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setFont(g2.getFont().deriveFont(30f));
g2.setColor(Color.red);
g2.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
String str = "Test String";
float location_x = 200;
float location_y = 200;
// will draw string horizontally
TextUtilities.drawAlignedString(str, g2, location_x, 
        location_y, TextAnchor.CENTER_LEFT);
// will draw string Vertically
TextUtilities.drawRotatedString(str, g2, -Math.PI / 2,
        location_x, location_y);
g2.dispose();
// generate png file from the modified buffered image
String path = "/sample/test.png";
try {
  ImageIO.write(image, "png", new File(path));
} catch (IOException e) {
  System.out.println("Error While Creating chart");
  e.printStackTrace();
}